-
Notifications
You must be signed in to change notification settings - Fork 607
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
[heft] heft-jest-plugin crashes on ESM tests (even though jest alone works fine on them) #4417
Comments
Hi @ChristophP, I see here https://github.com/ChristophP/heft-jest-esm/blob/main/packages/lib/config/heft.json that you don't use typescript plugin, The idea is to compile it to the javascript ( cjs or esm) then run tests on that code, not on the typescript code. If you want to run jest on the typescript files you should use |
Hi @woss , |
i am not sure, i didn't move any of my code to pure ESM + heft-jest yet, although I would suggest 2 things:
|
It seems to work like this with the latest version of heft and the heft-jest-plugin https://github.com/ChristophP/heft-jest-esm/compare/get-esm-to-work. |
I the solution is we got it to work by upgrading Heft to 0.6+ and the heft jest plugin accordingly. Note to Rush maintainers: Feel free to close this |
To date we haven't done any work on enabling Jest's native ESM support, since it still has a number of open issues and requires experimental flags. |
I understand. Yeah, it's a pain. Jest's ESM support has been experimental for years. And that's not even through fault of their own, it's because they are using (and need to) use NodeJS's |
Btw judging from this thread that situation seems to be quite frustrating for the Jest maintainer's as well |
@dmichon-msft - Do you know how much work this would be to add support for? |
I don't wanna speak for @dmichon-msft , but from how I understand it, there is no extra work to be done by heft or the jest-pluginto support ESM in Jest. It already works if some preconditions are met
So I believe it's mostly a matter of stating that it works in the heft docs, and linking to jest's docs about how to use it. |
What is the best way to set this up in a cross-platform rush+heft monorepo? The best I managed is to use cross-env in the package.json of every project:
This seems to work, but I would prefer a solution where I don't have to repeat the cross-env noise in every package.json. Ideas:
|
Summary
We are converting our repo to ESM. (There is no way around it, since some depencies won't support CommonJS anymore, ESM can import CJS and ESM, CJs can only require CJS).
Our
tsconfig.json
usesmodule: NodeNext
andmoduleResolution: NodeNext
and our package.json containstype: module
.Everything including the build works well except for our jest tests which use
heft-plugin-jest
.We see an error like this (which is common when Jest is run on ESM code without
NODE_OPTIONS=--experimental-vm-modules
set).However, this must be something heft specific ,as the same tests DO WORK when run through jest alone but not when run through heft.
Repro steps
This repo contains a minimal example to reproduce the issue. It also highlights how the same tests run under jest alone but not with the heft-jest-plugin.
Expected result: Heft uses Jest to run the tests.
Actual result: Heft uses Jest and crashes saying it doesn't recognize
import
(which it should in an ESM context)Details
Heft seems to do something unusal. Since for some reason it doesn't seem to respect the
NODE_OPTIONS=--experimental-vm-modules
flag. When run with jest alone the tests are run just fine.Probably the best way to fix this is to find out the difference between the
rushx jest-only
andrushx heft-breaks
command in the demo repo and make sureheft
works the same way as it would if only jest were run in terms of treatment of ESM.Standard questions
Please answer these questions to help us investigate your issue more quickly:
@rushstack/heft
version?node -v
)?The text was updated successfully, but these errors were encountered: