Skip to content

dynamic imports create a double default-wrapped export - e.g. { default: { default: Foo } } #273

@magicmark

Description

@magicmark

Repro

Runnable repro: https://stackblitz.com/edit/markl-ts-jest-repro-gbovnq?file=README.md

Relevant files:

foo.ts

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

bar.ts

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

tsconfig.json

{
  "extends": ["@tsconfig/node20/tsconfig.json"],
  "include": ["src/**/*"]
}

Actual vs Expected 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 is that it produces the following output:

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

(stackblitz runs on node 18, but this reproduces exactly on LTS (20) as well)

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions