Description
π Search Terms
"resolution-mode"
π Version & Regression Information
I was unable to test this on prior versions because the @import
tag is newly available on TS 5.5.2
β― Playground Link
No response
π» Code
// @filename: esm/esm.js
export type MyType = { foo: 'bar' }
// @filename: cjs/cjs.js
// This works:
/** @typedef {import('../esm/esm.js', { with: { 'resolution-mode': 'import' } }).MyType} MyType */
// This doesn't:
/** @import {MyType} from '../esm/esm.js' with { 'resolution-mode': 'import' } */
I couldn't create a TS playground because of this issue: #52666
π Actual behavior
The @import
usage in this context yields the following error:
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("../esm/esm.js")' call instead.
To convert this file to an ECMAScript module, change its file extension to '.mjs', or add the field "type": "module" to '/cjs/package.json'. ts(1479)
π Expected behavior
The @import
tag should account for import attributes like with { 'resolution-mode': 'import' }
to enable cross CJS/ESM type imports.
Additional information about the issue
No response