Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: dynamic imports create a double default-wrapped export -- { default: { default: MyDefaultExport } } #4448

Closed
magicmark opened this issue Jul 12, 2024 · 2 comments

Comments

@magicmark
Copy link

magicmark commented Jul 12, 2024

Version

29.2.1

Steps to reproduce

foo.ts

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

foo.test.ts

it('should be a foo', async () => {
  const foo = await import('../src/foo');
  console.log(foo);

  // Expected assertion (does not currently work) - this throws :(
  // expect(typeof foo.default).toBe('function');

  // This currently passes :(
  expect(typeof foo.default.default).toBe('function');
});

Repro link on github: https://github.com/magicmark/ts-jest-repro-1

You can run it in stackblitz here:

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]
}

Debug log

https://i.fluffy.cc/j8klVXNFT1pr5733Hq1SBcz1Q3N6Z6PH.html

Additional context

No response

Environment

System:
  OS: Linux 5.0 undefined
  CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
  Node: 18.20.3 - /usr/local/bin/node
  Yarn: 1.22.19 - /usr/local/bin/yarn
  npm: 10.2.3 - /usr/local/bin/npm
  pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
  jest: ^29.7.0 => 29.7.0
@magicmark
Copy link
Author

Hmm i'm actually seeing this reproing outside of ts-jest, maybe i'm in the wrong place...

src/bar.ts

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

main();

$ npx tsc && node build/bar.js produces the same output 😢

@magicmark
Copy link
Author

Looks like this is just a typescript config issue: tsconfig/bases#273

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant