`"module": "NodeNext"` seems to ignore `package.json`'s `"type": "module"`
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 238
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
Reproduction:
1. Clone https://github.com/fromdeno/deno2node
2. Run `src/cli.ts --module nodenext` in its directory.
Expected result: successfully emits ESM, since `package.json` specifies `"type": "module"`
Actual result: `ts-morph` 19.0.0 emits broken CJS:
```
src/init.ts:13:49 - error TS1470: The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.
13 const packageUrl = new URL("../package.json", import.meta.url);
~~~~~~~~~~~
src/init.ts:45:47 - error TS1470: The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.
45 const denoJsonUrl = new URL("../deno.json", import.meta.url);
~~~~~~~~~~~
src/init.ts:46:51 - error TS1470: The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.
46 const tsconfigUrl = new URL("../tsconfig.json", import.meta.url);
~~~~~~~~~~~
TypeScript 5.1.3
Found 3 errors.
```
Contributor guide
Research direction
Clone the linked deno2node reproduction and run src/cli.ts --module nodenext. Read src/init.ts and inspect how ts-morph 19.0.0 handles package.json's type field and NodeNext module detection. Done means the reproduction emits ESM successfully without the reported TS1470 errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100