-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed as not planned
Closed as not planned
Copy link
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
Milestone
Description
Bug Report
🕗 Version & Regression Information
I observed this in TypeScript 4.9.x, couldn't test earlier versions.
💻 Code
tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"target": "ESNext",
"module": "CommonJS",
"outDir": "dist",
"lib": ["ESNext", "DOM"],
"esModuleInterop": false,
"declaration": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"sourceMap": true,
"moduleResolution": "nodenext",
"baseUrl": "."
},
"include": ["index.ts"]
}
package.json:
{
"dependencies": {
"got": "^12.5.3",
"typescript": "^4.9.5"
}
}
index.ts:
import type { Headers } from 'got'
const foo: Headers = {}
console.log(foo)
🙁 Actual behavior
Error reported:
index.ts:1:30 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("got")' call instead.
To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '/Volumes/DATI/Users/Shogun/Programmazione/Test/got/package.json'.
1 import type { Headers } from 'got'
~~~~~
Found 1 error in index.ts:1
Note the got is just a quick repro example. It happening with any ESM module.
🙂 Expected behavior
Since I'm just doing import type
, the emitted file has no requires at all and thus the error is unnecessary.
Finesse, behruzrahimov, voxpelli, dagnelies, Xunnamius and 3 more
Metadata
Metadata
Assignees
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.