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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add info about ES modules to docs #10611
Conversation
With the warnings out of the way, this is how you activate ESM support in your tests. | ||
|
||
1. Ensure you either disable [code transforms](./configuration#transform-objectstring-pathtotransformer--pathtotransformer-object) by passing `transform: {}` or otherwise configure your transformer to emit ESM rather than the default CommonJS (CJS). | ||
1. Execute `node` with `--experimental-vm-modules`, e.g. `node --experimental-vm-modules node_modules/.bin/jest` or `NODE_OPTIONS=--experimental-vm-modules npx jest` etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My tests for tslib didn't need these flags, just making sure that the root package json is a "type": "module"
- https://github.com/microsoft/tslib/tree/master/test/esm-node-native
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orta
That鈥檚聽because your聽tests don鈥檛聽use聽Jest, which聽runs聽tests in聽vm
聽contexts, where聽the聽Module
聽API needs聽that聽flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, see the https://nodejs.org/api/vm.html#vm_class_vm_module link above.
EDIT: Ergh, same link as @ExE-Boss posted 馃槄
Co-authored-by: Micha毛l Zasso <targos@protonmail.com>
This might need a quick followup: the documented way of invoking with the experimental flag set through an env var does not work on Windows, requiring |
@Pomax wanna send a PR tweaking the text to work on all platforms? |
I don't know what your policy on "backing" third party tools is, so I have no idea what a PR would look like, here, whereas you probably do. I can heartily recommend tell folks to use cross-env for anything that relies on command line env vars if things need to work cross-platform, but I have no idea what Facebook's policy is, and I'm very much not up for signing a CLA just to submit a docs PR... though if docs PRs are exempt I can write something up? |
I can't imagine FB having a policy on that (I don't work there). I understand not wanting the sign the CLA, if just sticking CRA just documents how to do it on different platforms, but I think that's also for educational purposes, which is not really relevant for us here: https://create-react-app.dev/docs/adding-custom-environment-variables/#adding-temporary-environment-variables-in-your-shell (they do use |
yep, docs wise that's perfect, thanks! |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Ref #9430 (comment)
I haven't written too much, but it's something. Added it to all
jest@26
versioned docs.Test plan
馃し