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
Missing documentation using jest with repos that are "type":"module" ("Cannot use import statement outside a module") #10380
Comments
You have to run |
Thanks, that's a useful link, but indeed: the issue is mostly about getting that documented so that people searching the Jest docs can actually get an answer to "can I used this and if so, how?". |
It's briefly mentioned in the blog posts (https://jestjs.io/blog/2020/05/05/jest-26#native-esm-support), but I don't think that shows up in search. PR welcome adding a note that's it WIP and experimental 🙂 |
I'd rather someone who actually knows the docs writes that PR so it's in the right place in a way that's easily discoverable. I have way too many things to do to first learn a documentation codebase I'm afraid. |
Somewhat fixed via #10611, although it's very much incomplete |
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. |
Running jest in a repo with a package.json that clearly indicates
"type": "module"
, with test code that also follows esmodule format, causes Jest to error out:results in:
Which doesn't make a lot of sense: the project is clearly marked as being modern module-based code, Node 14 has zero problems with running any of the code, but Jest does not seem to "see" that we're working in a modern codebase rather than a CJS codebase.
I can't find anything in the docs that explains how to tell Jest that everything is module code, and that it should run as such. I don't see anything that explains which runtime flag is required (e.g.
npx jest --esmodule
?) or which explicit config setting is necessary to make this work (also of course I hope this doesn't require writing an explicit conf file, because zero conf is the best conf).If this is in the docs, then it might be undiscoverable: searching for "module" or "esmodule" on https://jestjs.io/docs/en/ only finds sections relating to mocks.
If it's not in the docs, but Jest should be able to deal with this, then that should probably get added to the docs.
If it's not in the docs, and Jest can't deal with this, then that should definitely be added to the docs, as new JS projects in 2020 don't need ES5 conversion anymore, except for legacy support, so you'd expect Jest to be deal with test files that are modules as fine as Node itself =)
The text was updated successfully, but these errors were encountered: