msw: segfault in jest with msw@2.0.7

Prerequisites

Environment check

  • I’m using the latest msw version
  • I’m using Node.js version 18 or higher

Node.js version

v18.16.1

Reproduction repository

https://github.com/mswjs/examples/tree/main/examples/with-jest

Reproduction steps

cd examples/with-jest

nvm use 18.16.1

npm i msw@2.0.7

npm run test

Current behavior

The tests crash with a segfault.

with-jest % npm run test

test jest

RUNS ./example.test.ts zsh: segmentation fault npm run test

Expected behavior

I expect the tests to pass without segfault.

nvm use 18.16.1

npm i msw@2.0.6

npm run test
  • works fine, so it definitely has something to do with the last release of msw.

This testcase in test repo also somehow does get fixed by upping the version of node, but the one in my project (which is more complicated, so i don’t really want to try and recreate it exactly) does not.

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Reactions: 9
  • Comments: 25 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Confirming that the fix works for us - thank you!

Works, it’s magic ❤️

Node: 18.18.0

I can confirm that 2.0.9 works with the following environment.

React Native: 0.72.3 Msw: 2.0.9 Node.JS: 21.2.0

Both Jest and the development environment work perfectly. Once again thank you!

Released: v2.0.9 🎉

This has been released in v2.0.9!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Once again, @mattcosta7 is a pure magician 🪄

Hope you’ll have the error with this minimal reproduction : https://github.com/bengeois/msw-segfault-issue

I agree this is likely to do with the node:events import but I would like to have a reliable reproduction. Does anybody have one?

I’m trying to make a reproduction project but the error seems to not appear systematically

segfault-handler produces a log like this:

0   segfault-handler.node               0x000000010e60101c _ZL16segfault_handleriP9__siginfoPv + 296
1   libsystem_platform.dylib            0x00000001a909aa24 _sigtramp + 56
2   node                                0x0000000100d683ec _ZN4node6loaderL23ImportModuleDynamicallyEN2v85LocalINS1_7ContextEEENS2_INS1_4DataEEENS2_INS1_5ValueEEENS2_INS1_6StringEEENS2_INS1_10FixedArrayEEE + 232
3   node                                0x000000010103cccc _ZN2v88internal7Isolate38RunHostImportModuleDynamicallyCallbackENS0_6HandleINS0_6ScriptEEENS2_INS0_6ObjectEEENS0_11MaybeHandleIS5_EE + 852
4   node                                0x000000010141edc0 _ZN2v88internal25Runtime_DynamicImportCallEiPmPNS0_7IsolateE + 276
5   node                                0x00000001017692c4 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvInRegister_NoBuiltinExit + 100
6   node                                0x00000001017fe1bc Builtins_CallRuntimeHandler + 92
7   node                                0x00000001016f4198 Builtins_InterpreterEntryTrampoline + 248
8   node                                0x00000001016fea34 Builtins_LoadIC_NoFeedback + 1492
9   node                                0x00000001017f5644 Builtins_GetNamedPropertyHandler + 5092
10  node                                0x00000001016f4198 Builtins_InterpreterEntryTrampoline + 248
11  node                                0x00000001017280d0 Builtins_GeneratorPrototypeNext + 144
12  node                                0x00000001016f4198 Builtins_InterpreterEntryTrampoline + 248
13  node                                0x00000001017b2b88 Builtins_PromiseConstructor + 2312
14  node                                0x00000001016f1914 Builtins_JSBuiltinsConstructStub + 340

So it’s likely to do with an async import of node:events (https://github.com/mswjs/msw/pull/1858)