-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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]: tslib 2.5.2 package.json exports change breaks Jest when using ESM modules #14173
Comments
The issue is that Jest now resolves to https://www.runpkg.com/[email protected]/tslib.es6.js instead of https://www.runpkg.com/[email protected]/modules/index.js (this is correct according to the stanza) The latter is in a directory with a I think Jest's behaviour here is correct (we cannot know which condition we hit, so we cannot know if the returned file should be interpreted as ESM or not), but it seems unlikely |
microsoft/tslib#201, fwiw |
Commented over there. |
@SimenB I have added a minimal project to demonstrate the bug here: |
@SimenB The issue was introduced in [email protected]. Notice that the issue disappears if you downgrade tslib in my sample to 2.5.0. Jest should support We anyway need a temporary workaround. Any suggestion? |
Temporary workaround is to plug in your own resolver (using |
@SimenB I have updated my sample project with a custom resolver built on |
@SimenB Please see my comment microsoft/tslib#201 (comment). Maybe it would be better to align with enhanced-resolve whenever this this type of exports ambiguity is encountered? FYI: I was anyway able to make a temporary workaround by adding node as a fallback custom export condition to my jest config for now.... {
//...
testEnvironmentOptions: {
customExportConditions: ["browser", "node"] // "node" is required for a tslib issue
}
} |
As mentioned in that issue, That said, they fixed it: https://github.com/microsoft/tslib/releases/tag/v2.5.3 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Version
29.5.0 (latest)
Steps to reproduce
Context
I have a TypeScript project that compiles to true ESM modules (moduleResolution/module NodeNext), and all ".ts" imports use ".js" extensions as recommended in TypeScript. The project uses f.ex. TypeScript
experimentalDecorators
and it usesimportHelpers
which adds a dependency totslib
.My jest config looks as follows:
To support ESM, I run the tests with:
node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js
This setup is following the jest/ts-jest documentation, and should be standard for ESM support in TypeScript projects.
The Jest bug
After upgrading tslib from v2.5.0 to v2.5.2, the Jest tests fail.
This is because tslib's
exports
in package.json has changed with the update, and it seems like the Jest's resolver does not support the more verbose export syntax.tslib@2.5.0 package.json exports:
tslib@2.5.2 package.json exports:
When I just copy the exports from 2.5.0 and replace the ones in 2.5.2 in *node_modules/tslib/package.json, the tests run just fine.
PS! This error only seems to happen when using jest config
envirnoment: "jsdom"
. When setting it to"node"
, the problem is not triggered. It looks like this may be a jest-environment-jsom specific issue.I have tested configuring jest with
moduleNameMapper
to forcetslib
to use:...but none of these fixed the issue.
Expected behavior
The tests should work like before
Actual behavior
Additional context
My tsconfig.json file looks as follows:
Environment
The text was updated successfully, but these errors were encountered: