Jest runtime blows up if internals are not defined in ES module
🐛 Bug Report
Simple test to test ESM imports fails with ReferenceError: Export '__signal_exit_emitter__' is not defined in module.
To Reproduce
The issue can be reproduced in this codesandbox by opening a new terminal and running: yarn rebuild && yarn test importESModule.test.js
If you prefer, you can also clone https://github.com/mekwall/ffmpeggy/tree/jest-runtime-esm-import-bug and do the same.
The test looks like this:
describe("import ES modules", () => {
it("should be able to import", async () => {
if (process.version.startsWith("v12")) {
// Next line blows up on v12 so let's skip this for now
return;
}
// Jest runtime blows up with the next line
const module = await import("../../es/index.mjs");
expect(module.FFmpeggy).toBeDefined();
const ffmpeggy = new module.FFmpeggy();
expect(ffmpeggy).toBeInstanceOf(module.FFmpeggy);
});
});
Steps to reproduce the behavior:
- Check out the repo
- Install the deps with
npm installoryarn - Build with
npm run rebuildoryarn rebuild - Run the
importESModule.test.jswith jest (don't forget to pass the--experimental-vm-modulesflag)
Expected behavior
Jest runtime should not blow up if internals are not defined in the module.
envinfo
System:
OS: Linux 5.13 Manjaro Linux
CPU: (20) x64 Intel(R) Core(TM) i9-10900K CPU @ 3.70GHz
Binaries:
Node: 16.6.2 - ~/.nvm/versions/node/v16.6.2/bin/node
Yarn: 1.22.11 - ~/.nvm/versions/node/v16.6.2/bin/yarn
npm: 7.20.1 - ~/repos/ffmpeggy/node_modules/.bin/npm
npmPackages:
jest: ^27.0.6 => 27.0.6
Any updates or workaround on this bug?
I am experiencing this issue as well.
FAIL test/hello.test.ts
● Test suite failed to run
ReferenceError: Export '__signal_exit_emitter__' is not defined in module
at node_modules/.pnpm/[email protected]/node_modules/jest-runtime/build/index.js:1540:16
at Array.forEach (<anonymous>)
at async Promise.all (index 0)
at async Promise.all (index 5)
at async Promise.all (index 6)
at async Promise.all (index 0)
at async Promise.all (index 0)
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
Also running into this issue:
FAIL test/unit/styles.test.ts
● Test suite failed to run
ReferenceError: Export '__signal_exit_emitter__' is not defined in module
at node_modules/jest-runtime/build/index.js:1542:16
at Array.forEach (<anonymous>)
FAIL test/unit/treatments/media.treatment.test.ts
● Test suite failed to run
ReferenceError: Export '__signal_exit_emitter__' is not defined in module
at node_modules/jest-runtime/build/index.js:1542:16
at Array.forEach (<anonymous>)
FAIL test/unit/renderers/article.renderer.test.ts
● Test suite failed to run
ReferenceError: Export '__signal_exit_emitter__' is not defined in module
at node_modules/jest-runtime/build/index.js:1542:16
at Array.forEach (<anonymous>)
FAIL test/unit/util.test.ts
● Test suite failed to run
ReferenceError: Export '__signal_exit_emitter__' is not defined in module
at node_modules/jest-runtime/build/index.js:1542:16
at Array.forEach (<anonymous>)
FAIL test/unit/renderers/renderer.builder.test.ts
● Test suite failed to run
ReferenceError: Export '__signal_exit_emitter__' is not defined in module
at node_modules/jest-runtime/build/index.js:1542:16
at Array.forEach (<anonymous>)
FAIL test/unit/treatments/article.treatment.test.ts
● Test suite failed to run
ReferenceError: Export '__signal_exit_emitter__' is not defined in module
at node_modules/jest-runtime/build/index.js:1542:16
at Array.forEach (<anonymous>)
FAIL test/unit/urlRewriting.test.ts
● Test suite failed to run
ReferenceError: Export '__signal_exit_emitter__' is not defined in module
at node_modules/jest-runtime/build/index.js:1542:16
at Array.forEach (<anonymous>)
Please provide a minimal reproduction, the one provided in the OP is quite large
It probably has something to do with using process.exit() since that's what's in the stack trace, and both @mekwall 's codebase and mine have exit calls. Theirs has this.emit("exit", 1, e); and we have process.exit(1)
Also getting these log messages if it helps:
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From test/e2e/en.e2e.test.ts.
Okay I cut down the linked repo viciously until I had a minimally reproducible case. Then I bumped jest to latest release and the bug went away. You can close this one.