Skip to content

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

Closed
@nicolo-ribaudo

Description

@nicolo-ribaudo

πŸ”Ž 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:

export let a = 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

Assignees

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