Skip to content
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

Lazy/Dynamic import causes jest worker to fail #48

Open
AlonMiz opened this issue Aug 3, 2021 · 0 comments
Open

Lazy/Dynamic import causes jest worker to fail #48

AlonMiz opened this issue Aug 3, 2021 · 0 comments

Comments

@AlonMiz
Copy link

AlonMiz commented Aug 3, 2021

  ● Test suite failed to run

    Call retries were exceeded

      at ChildProcessWorker.initialize (../../node_modules/jest-worker/build/workers/ChildProcessWorker.js:193:21)

making this part sync require fixes the issue
image

related to this thread: jestjs/jest#8769
doesn't happen in ts-jest.

were able to get more informed error by simplifying the case

Error
: 
    at invariant (/node_modules/jest-runtime/build/index.js:2004:11)
    at importModuleDynamically (/node_modules/jest-runtime/build/index.js:1362:11)
    at importModuleDynamicallyWrapper (node:internal/vm/module:448:21)
    at exports.importModuleDynamicallyCallback (node:internal/process/esm_loader:30:14)

reproduce:
test.js

import {getModuleLazy} from './lazy'
describe('some test', () => {
  test("amazing test", async () => {
     await getModuleLazy()
  })
})

lazy.js

export const getModuleLazy = () => {
  return import('lodash').then(mod => {
    console.log(mod);
  });
};

UPDATE:
updated to jest 27, got this error, which is more informative:

Error: You need to run with a version of node that supports ES Modules in the VM API. See https://jestjs.io/docs/ecmascript-modules
    at invariant (/node_modules/jest-runtime/build/index.js:2137:11)
    at importModuleDynamically (/node_modules/jest-runtime/build/index.js:1486:11)
    at importModuleDynamicallyWrapper (node:internal/vm/module:448:21)
    at exports.importModuleDynamicallyCallback (node:internal/process/esm_loader:30:14)

were able to follow some of the instructions in the doc. after adding --experimental-vm-modules to the node jest command manually, the test passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant