-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
segfault when running jest tests in fastify with esm mode #43083
Comments
I can repro. I don't know if any of your dependencies make use of native addons. If they don't, then this is most likely a bug in node or one of its dependencies (e.g., V8). |
cc @nodejs/vm |
Thank you for looking into it! |
@dlemperFuchs What does |
|
I have the same problem, but with testing. If I run stanley in ~/dev/app-api on main λ npm run test
> [email protected] test
> node --experimental-vm-modules node_modules/jest/bin/jest.js test/
(node:8929) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
PASS test/routes/root.test.ts
✓ default root route (111 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 3.334 s
Ran all test suites matching /test\//i.
But after a second attempt, it fails: stanley in ~/dev/app-api on main λ npm run test
> [email protected] test
> node --experimental-vm-modules node_modules/jest/bin/jest.js test/
(node:8967) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
RUNS test/routes/root.test.ts
[1] 8956 segmentation fault (core dumped) npm run test
|
I'm getting a very similar stack trace for Node v16.14.0 + v14, and Jest v27.5.1. I would make it cleaner if I knew how -- I think I am missing some debug symbols. If someone can help? I get this error intermittently: but it's generally when loading https://github.com/seriousme/fastify-openapi-glue -- which uses ESM. But it's ALWAYS when using Jest. This library loads fine when I run the server outside of tests. Also, there's no |
I am doing some further testing: Test order matters. Could it be a race condition? When running unit tests (no ESM) first and service tests (ESM) after in the same session, no crashes occur.
|
Fixed the issue by properly loading ESM, and everything that entails in doing so. Simply put: I wasn't handling ESM at all. I was simply using a normal import in TypeScript, which transpiles to a CJS require. I changed my project to handle ESM, and used top-level await on a dynamic import(). This is still obviously a bug because Node should properly handle this and error. That maybe gives some insight into the problem. |
@xbc5 you fixed it by simply using a dynamic import instead of a "normal" import? Would you mind having a look at my repo and tell me, what I can change to get it working? I tried several changes of the imports and didn't get it working. As I already invested many hours, my company wants me to switch to a working solution (node-tap in this case), so this bug will not affect me any longer. |
This is probably fixed in 20.8 via #48510. |
Version
v16.15.0
Platform
Linux main-deb 5.10.0-0.bpo.11-amd64 #1 SMP Debian 5.10.92-1~bpo10+1 (2022-02-03) x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
git clone https://github.com/dlemperFuchs/fastify-jest-esm-segfault cd fastify-jest-esm-segfault npm install NODE_OPTIONS=--experimental-vm-modules npx jest
How often does it reproduce? Is there a required condition?
reproducible every time
What is the expected behavior?
Jest runs tests in the repo
What do you see instead?
Additional information
Sorry, I'm quite unsure if this is a node problem or a jest or fastify problem. I tried several things within about 40 hours but nothing worked and in my opinion a segfault shouldn't happen while JS code gets executed.
The text was updated successfully, but these errors were encountered: