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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect ESM config loading in 25.5.2 #9935

Closed
aldeed opened this issue Apr 30, 2020 · 4 comments
Closed

Incorrect ESM config loading in 25.5.2 #9935

aldeed opened this issue Apr 30, 2020 · 4 comments

Comments

@aldeed
Copy link

aldeed commented Apr 30, 2020

馃悰 Bug Report

In a new project using Jest 25.5.2 and Node 12.16.0, using a Jest config file that is an ES module results in an error: TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.

To Reproduce

https://github.com/aldeed/jest-esm-config-issue#how-to-run-and-see-error

Expected behavior

  1. Whether it has .mjs extension or nearest package.json has type: "module", the config file should be loaded identically as an ES module, and there should not be errors.
  2. Because of the above expectation, jest --init command should detect the type: "module" and create the config with export default rather than module.exports = .

Link to repl or repo (highly encouraged)

https://github.com/aldeed/jest-esm-config-issue

envinfo

  System:
    OS: macOS 10.15.3
    CPU: (4) x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
  Binaries:
    Node: 12.16.0 - ~/.nvm/versions/node/v12.16.0/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v12.16.0/bin/npm
  npmPackages:
    jest: ^25.5.2 => 25.5.2 
@aldeed
Copy link
Author

aldeed commented Apr 30, 2020

Opened at request of @SimenB here: #9430 (comment)

@SimenB
Copy link
Member

SimenB commented Apr 30, 2020

Thanks! I'll take a look tonight

@SimenB
Copy link
Member

SimenB commented May 1, 2020

Looked now - this is a bug in Node. If you remove the --experimental-vm-modules flag, this is the error: Error: Jest: Your version of Node does not support dynamic import - please enable it or use a .cjs file extension for file /Users/simen/repos/jest-esm-config-issue/jest.config.js

Node 12 requires a flag to activate https://nodejs.org/docs/latest-v12.x/api/esm.html#esm_enabling

Adding that makes the test pass.

I've opened a bug report: nodejs/node#33202

@SimenB SimenB closed this as completed May 1, 2020
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants