dsherret / dsherret/ts-morph

`"module": "NodeNext"` seems to ignore `package.json`'s `"type": "module"`

Open
#1,446 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.