-
Notifications
You must be signed in to change notification settings - Fork 267
Closed
Labels
Description
Environment:
Node: 18
Typescript: 5.0.4
Steps to reproduce:
- Create a simple project with typescript 5 and configs:
npm i -D @tsconfig/strictest @tsconfig/node18 typescript @types/node
- Create a
index.ts
file with following contents
import { readFileSync } from 'node:fs';
export function test() {
console.log(readFileSync('./index.ts'))
}
- Use
tsconfig.json
from README:
{
"extends": ["@tsconfig/strictest/tsconfig", "@tsconfig/node18/tsconfig"]
}
- Compile code using
tsc
Expected result:
Code compiles without errors.
Actual result:
Code compilation fails with errors:
src/index.ts:1:10 - error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled.
1 import { readFileSync } from 'node:fs';
~~~~~~~~~~~~
src/index.ts:3:1 - error TS1287: A top-level 'export' modifier cannot be used on value declarations in a CommonJS module when 'verbatimModuleSyntax' is enabled.
3 export function test() {
~~~~~~
Extras:
Nether using "type": "module"
in package.json, nor using .mts
, .cts
extensions not helping.
Suggestions:
- Maybe it worth to set
"verbatimModuleSyntax": false,
in all node* configs, unless they have"module": "commonjs"
- Move
"verbatimModuleSyntax": true,
to@tsconfig/esm
, since it doesn't works only with esm.
Related to #161