-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
SyntaxError: Cannot use import statement outside a module #9938
Comments
By default,
For further reference, please check: jestjs/jest#6229 (comment) |
Thanks a lot @ehfeng, it works perfectly well! Even the |
I got the same error. After many days of struggling, trying all sorts of different configs, setting It seems as though the Edit:
My external module that's in |
npm i babel-jest And I changed the |
See facebook/create-react-app#9938, specifically the solution in facebook/create-react-app#9938 (comment)
See facebook/create-react-app#9938, specifically the solution in facebook/create-react-app#9938 (comment)
You are my savior. This problem drove me mad two days and only your solution fixed it |
Thanks man |
Thank you so much. So annoying to see last test failing because of axios import module. |
Perfect, This worked for me. Cheers mate |
Hello 👋
Describe the bug
I want to run unit tests against my React application.
Unfortunately one of the dependencies I am using is only packaged for ES Modules* and it looks as if the default configuration coming with CRA 4.x is not able to deal with it out-of-the-box.
* "type": "module"
When calling
yarn test
I get the following error (which looks as if I was mixing import with require):While facing this issue I tried to shrink the issue to its simplest case so I also tried without CRA just by using only Jest and it worked as charm (on normal js files without all the babel part).
Did you try recovering your dependencies?
Which terms did you search for in User Guide?
ES Modules, mjs
Environment
Steps to reproduce
In order to reproduce you can have a look to this minimal reproduction repository: https://github.com/dubzzz/codemirror-next-repro-cra.
cd test-in-cra
yarn
yarn test
In the repository I also tried to run a test on a file using this package using jest only (see test-in-jest-esm). It required some changes like passing the option
--experimental-vm-module
to node.But I have not succeeded to do the same kind of trick when running Jest through CRA. Passing the flag does not seem to be enough as babel keeps transpiling the import to require when running the test.
Expected behavior
It should run fine when I try to run a test against a file importing a package only designed for ES Modules.
Actual behavior
It crashes.
Reproducible demo
Repro: https://github.com/dubzzz/codemirror-next-repro-cra
See Steps to reproduce
The text was updated successfully, but these errors were encountered: