-
-
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]: Unexpected token 'export' when Jest test imports d3 (7.1.1) #12036
Comments
I had the same problem yesterday. |
I'm having this problem as well with the "unified" module, which is an ESM only module. This is on Node v12 on a recent MacBook Pro. [email protected] |
I have a React project created with Nx and I am using TypeScript, I have [email protected] and I also receive the same error. I tried transformIgnorePatterns, which didn't work. |
@istvandesign did the workaround I ended up with work for you? so adding this to your jest config: moduleNameMapper: {
'd3': '<rootDir>/node_modules/d3/dist/d3.min.js',
}, |
I had to use the "transformIgnorePatterns": [
"/node_modules/(?!d3|d3-array|internmap|delaunator|robust-predicates)"
], I had to do this with multiple modules. |
mapping the |
ran into this issue in a moduleNameMapper: {
...
+ "^d3-(.*)$": `d3-$1/dist/d3-$1`
} I'm not sure if all |
beyond that, this is a usage question and not a bug, so closing this |
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
27.3.1
Steps to reproduce
We use Typescript, if our test file (*.spec.ts) contains the following import
Expected behavior
Test runs without problems
Actual behavior
Running the test will give the following error:
Additional context
The issue started when updating Jest from
26.6.3
to27.3.1
.I finally found a workaround for this. I first found this Jest issue #2550 it mentioned setting up
transformIgnorePatterns
and adding"allowJs": true
to ourtsconfig.json
. This did not work, what did solve it in the end was adding the following to ourjest.config.js
:Which makes it import from that minified file instead of
node_modules/d3/src/index.js
. Not sure if it is reasonable and possible for Jest to import from a module's dist folder when it cannot import from the index file? Also not sure if this is an issue with d3 or a mismatch with all the different ways in which you can express JavaScript (ESM/CommonJS/...)?Environment
System: OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo) CPU: (16) x64 Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz Binaries: Node: 14.16.1 - /tmp/fnm_multishells/13239_1636009783566/bin/node npm: 6.14.12 - /tmp/fnm_multishells/13239_1636009783566/bin/npm npmPackages: jest: 27.3.1 => 27.3.1
The text was updated successfully, but these errors were encountered: