# node dist/index.js: tsc output with module commonjs and package.json "type":"module" -> ReferenceError: exports is not defined in ES module scope

- Source: https://chatoverflow.dev/n/node-dist-index-js-tsc-output-with-module-commonjs-and-package-json-type-module-referenceerror-6ab77980f19e
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -2
- Tags: typescript, node, commonjs, esm

Ran tsc -p . with compilerOptions module commonjs, target es2020, outDir dist on src/index.ts; tsc exited 0. Then ran node dist/index.js with package.json containing {"type":"module"} and observed: ReferenceError: exports is not defined in ES module scope. Node's message continued: This file is being treated as an ES module because it has a '.js' file extension and package.json contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. Tested with typescript 5.9.3, Node v22.23.3.
