-
-
Notifications
You must be signed in to change notification settings - Fork 904
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
ESM Problems with Jest@26 and Node.js 14.x #451
Comments
Looks like "exports" is not supported yet. |
Had issues with ES exports and Jest see uuidjs/uuid#451
FWIW, tracking issue: jestjs/jest#9771 |
My workaround for this was to manually map the // jest.config.js
moduleNameMapper: {
// Force module uuid to resolve with the CJS entry point, because Jest does not support package.json.exports. See https://github.com/uuidjs/uuid/issues/451
"uuid": require.resolve('uuid'),
}, EDIT: This might not work depending on your projects dependency structure. See microsoft/accessibility-insights-web#5421 (comment) for a much better explanation.
EDIT: Please see #451 (comment) for an even more specific solution. |
Jest 28 does support it, see #616 for latest |
I can confirm #616 fixes this issue in my project using Jest 28 and jest-environment-jsdom. Thanks for working on it. |
So that seems like an awesome workaround, but it doesn't work if you're using a jest.config.mjs instead as you can't |
Thanks so much. This solved my problem which I was suffering since 15 hours. Altough I have jest 28 and did everything on StackOverflow nothing helped except this. This is my post on SO regarding my problem: https://stackoverflow.com/questions/73203367/this-annoying-jest-error-again-syntaxerror-unexpected-token-export/73203803#73203803 |
I have released |
Also add uuid@v9 as devDep to mitigate the issue uuidjs/uuid#451
Hi @ctavan, for my project we still need the workaround for jest tests to pass after updating to 9.0.0 with jest 29: # jest.config.js
module.exports {
moduleNameMapper: {
// Workaround for Jest not having ESM support yet
// See: https://github.com/uuidjs/uuid/issues/451
uuid: require.resolve('uuid'), |
Turns out mock service worker ( This caused an unexpected side effect when implementing the suggested
To resolve this, simply use a regex with an imperative start and end like so: moduleNameMapper: {
"^uuid$": require.resolve('uuid'),
} ✅ This ensures only the actual |
Note that |
@SimenB Yep, that's true and great that the root cause is fixed but until dependency packages are updated it's a waiting game. I'm using |
This commit bumps Jest to 29.4.1. This requires adding two additional development dependencies. As of Jest 28 `jest-environment-jsdom` is no longer shipped with Jest by default, and has therefore been added as a dependency. `uuid` was also added as a dev dependency. Jest 29 introduced some compatibility issues with `uuid` that were fixed in `uuid@9`: uuidjs/uuid#451 (comment) We import and use `uuid` in our tests, but as it was a dependencies dependency we did not control which version was installed. Version 8 (what was installed) causes Jest tests to fail like so: ``` SyntaxError: Unexpected token 'export' > 29 | import { v4 as uuidv4 } from 'uuid'; ```
This commit bumps Jest to 29.4.1. This requires adding two additional development dependencies. As of Jest 28 `jest-environment-jsdom` is no longer shipped with Jest by default, and has therefore been added as a dependency. `uuid` was also added as a dev dependency. Jest 29 introduced some compatibility issues with `uuid` that were fixed in `uuid@9`: uuidjs/uuid#451 (comment) We import and use `uuid` in our tests, but as it was a dependencies dependency we did not control which version was installed. Version 8 (what was installed) causes Jest tests to fail like so: ``` SyntaxError: Unexpected token 'export' > 29 | import { v4 as uuidv4 } from 'uuid'; ```
This commit bumps Jest to 29.4.1. This requires adding two additional development dependencies. As of Jest 28 `jest-environment-jsdom` is no longer shipped with Jest by default, and has therefore been added as a dependency. `uuid` was also added as a dev dependency. Jest 29 introduced some compatibility issues with `uuid` that were fixed in `uuid@9`: uuidjs/uuid#451 (comment) We import and use `uuid` in our tests, but as it was a dependencies dependency we did not control which version was installed. Version 8 (what was installed) causes Jest tests to fail like so: ``` SyntaxError: Unexpected token 'export' > 29 | import { v4 as uuidv4 } from 'uuid'; ```
This commit bumps Jest to 29.4.1. This requires adding two additional development dependencies. As of Jest 28 `jest-environment-jsdom` is no longer shipped with Jest by default, and has therefore been added as a dependency. `uuid` was also added as a dev dependency. Jest 29 introduced some compatibility issues with `uuid` that were fixed in `uuid@9`: uuidjs/uuid#451 (comment) We import and use `uuid` in our tests, but as it was a dependencies dependency we did not control which version was installed. Version 8 (what was installed) causes Jest tests to fail like so: ``` SyntaxError: Unexpected token 'export' > 29 | import { v4 as uuidv4 } from 'uuid'; ```
Hoping this can help everyone solve this problem
Even without the So in your
|
@pl12133 i love you buddy |
I'm still seeing this issue. uuid 9.0.0 and jest 29.4.0/29.5.0, and node 16.19.1 It looks like jest is not picking up the right version of the uuid module, opting for the one in esm-browser folder
I've tried coaxing it to force it to transpile, but have had no luck. |
GCS uses |
Based on advice here: uuidjs/uuid#451 (comment)
Hi, I'm using jest to test my project.
Trying to test a file where I import uuid results with an error:
I saw @Dps910 comment and I guess it's something similar.
I'm using UUID@8, node@14 and Jest@26 (and it's freshly-supported esm modules implementation).
Jest command:
node --experimental-vm-modules .\node_modules\jest\bin\jest.js
The file that I'm testing imports uuid like you suggested:
It fails only when I'm testing though.
Originally posted by @Tzahile in #245 (comment)
The text was updated successfully, but these errors were encountered: