-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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]: Cannot use import statement outside a module #12990
Comments
Or alternatively, if the error message itself is accurate, then why is my options.test.js not being treated as a "module"? If it so desperately wants it to be a module, then fine - make it a module, I don't give a fluff. As long as the tests execute, right? |
Same problem with
No bit of the documentation explains what to do to get Jest to understand this syntax, yet this part just willy-nilly assumes you've got some kind of magical configuration set up (that, again, is not mentioned anywhere) that makes Jest understand async/await. Very disappointing. |
Yes, I know, but it's 2022 and there's nothing experimental about this syntax. It should just work by itself. Edit: to clarify, the goal of this issue is not intended to get my tests to run. It got it. The intent is to actually fix this problem once and for all. It's well overdue, iyam. |
Yeah, they're already working on it. See #9430.
Might be best to close this issue and add your support in 9430 above then. Good luck! |
That issue dates from 2.5 years ago. Can I just ask how such a thing is taking that much time? I'm not impatient or anything, but 2.5 years is a long time... |
Feel free to follow nodejs/node#37648 and/or put in the work necessary in v8 in order for node to stabilise the API Jest uses. There is nothing jest can do here without the underlying platform moving forward. https://jestjs.io/docs/ecmascript-modules has instructions for how to use native ESM today. |
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
28.1.2
Steps to reproduce
jest
&babel-jest
"targets": { "node": "current" }
to the options for@babel/preset-env
in thebabel.config.json
transform: { "\\.js$": "babel-jest" }
to thejest.config.js
import X from X
at the topjest
Expected behavior
According to the documentation on how to deal with code that is 4 years old, i.e. contains
import
, it should now work.I would actually expect it to Just Work without any additional config. I mean, how can
import
not work? It works natively in Node.js absolutely fine, so why wouldn't it in Jest??Actual behavior
This is a relevant excerpt from the error message:
Additional context
I also can prove that the
babel-jest
transform produces code that still contains that top-levelimport
that Jest doesn't seem to like. So the problem (and perhaps the solution) might be in thebabel-jest
package.But more to the point, it should just work without needing any configuration. It's 2022 and this should've worked in 2018 without any config. Everything I "have to" configure to get this stuff to work, can be auto-detected. Or there should be more practical defaults to ship in Jest itself, that allow it to deal with modern code.
Environment
The text was updated successfully, but these errors were encountered: