Skip to content

[5.5 beta] package.json "type" lookup in non-Node.js module is unexpected #58663

Description

🔎 Search Terms

moduleDetection force legacy

🕗 Version & Regression Information

  • This changed in version 5.5-beta

⏯ Playground Link

No response

💻 Code

package.json:

{
"name": "ts-test",
"version": "1.0.0",
"description": "",
"type": "commonjs",
"devDependencies": {
"typescript": "^5.5.0-beta"
}
}

tsconfig.json:

{"include": ["src/index.ts"],"compilerOptions": {"module": "Preserve","verbatimModuleSyntax": true,"moduleDetection": "force","emitDeclarationOnly": true,"declaration": true,"declarationDir": "./dts"}}

src/index.ts:

exportleta=1;

🙁 Actual behavior

src/index.ts:1:1 - error TS1287: A top-level 'export' modifier cannot be used on value declarations in a CommonJS module when 'verbatimModuleSyntax' is enabled.
1 export let a = 1;

🙂 Expected behavior

Given that I'm using "moduleDetection": "force", that file is an ES module (regardless of what package.json#type says) and thus I shouldn't see that error. This was the behavior in 5.4.

Additional information about the issue

No response

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions