Skip to content

"module": "nodenext" causes dynamic imports to be double default-wrapped - e.g. { default: { default: Foo } }Β #59257

@magicmark

Description

@magicmark

@jakebailey says:

...this is a runtime issue with TypeScript's CJS import helpers, so the issue should be files on TypeScript.

πŸ”Ž Search Terms

dynamic import default wrapped

πŸ•— Version & Regression Information

"typescript": "^5.5.3"

⏯ Playground Link

https://stackblitz.com/edit/typescript-dynamic-import-issue?file=tsconfig.json,README.md%3AL6

And run this: $ npx tsc --outDir build && node build/bar.js

πŸ’» Code

foo.ts

export default function MyFoo() {
  return 'foo';
}

bar.ts

(async function main() {
  const foo = await import('./foo.js');
  console.log(foo);
})();

tsconfig.json

{
  "compilerOptions": {
    "module": "nodenext"
  },
  "include": ["src/**/*"]
}

πŸ™ Actual behavior

const foo = await import('../src/foo');
console.log(foo);

This produces the following output:

[Module: null prototype] {
  __esModule: true,
  default: { default: [Function: MyFoo] }
}

πŸ™‚ Expected behavior

Expected behavior is that it produces the following output:

[Module: null prototype] {
  __esModule: true,
  default: [Function: MyFoo]
}

Additional information about the issue

Initially raised here tsconfig/bases#273

Metadata

Metadata

Assignees

Labels

ExternalRelates to another program, environment, or user action which we cannot control.Working as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions