jest icon indicating copy to clipboard operation
jest copied to clipboard

Jest runtime blows up if internals are not defined in ES module

Open mekwall opened this issue 4 years ago • 8 comments

🐛 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:

  1. Check out the repo
  2. Install the deps with npm install or yarn
  3. Build with npm run rebuild or yarn rebuild
  4. Run the importESModule.test.js with jest (don't forget to pass the --experimental-vm-modules flag)

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

mekwall avatar Aug 13 '21 12:08 mekwall

Any updates or workaround on this bug?

rendaardy avatar Jan 17 '23 13:01 rendaardy

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)

jjangga0214 avatar Jun 01 '23 16:06 jjangga0214

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.

github-actions[bot] avatar May 31 '24 17:05 github-actions[bot]

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>)

audiodude avatar Jun 13 '24 06:06 audiodude

Please provide a minimal reproduction, the one provided in the OP is quite large

SimenB avatar Jun 13 '24 06:06 SimenB

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)

audiodude avatar Jun 14 '24 22:06 audiodude

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.

audiodude avatar Jun 14 '24 22:06 audiodude

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.

audiodude avatar Jun 26 '24 01:06 audiodude