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

require()ing a file shouldn't automatically make it CJS #11258

Closed
nicolo-ribaudo opened this issue Apr 1, 2021 · 5 comments · Fixed by #11260
Closed

require()ing a file shouldn't automatically make it CJS #11258

nicolo-ribaudo opened this issue Apr 1, 2021 · 5 comments · Fixed by #11260

Comments

@nicolo-ribaudo
Copy link
Contributor

nicolo-ribaudo commented Apr 1, 2021

🐛 Bug Report

When a .js file is required with require(), Jest assumes that it's a CJS file even when it is an ESM file.

To Reproduce

See repo below

Expected behavior

It should log ERROR! [ERR_REQUIRE_ESM] Must use import to load ES Module: because esm-dep.js is an ESM file, but it logs IMPORTED! { foo: 2 }.

Link to repl or repo (highly encouraged)

https://github.com/nicolo-ribaudo/jest-bug-require-esm

Note that package.json contains "type": "module".

envinfo

  System:
    OS: Linux 5.8 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Node: 14.16.0 - /usr/local/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 6.14.11 - /usr/local/bin/npm
  npmPackages:
    jest: ^27.0.0-next.6 => 27.0.0-next.6 

Ref #9430 (comment)

@SimenB
Copy link
Member

SimenB commented Apr 1, 2021

Good catch 👍 I'll fix some time during Easter 🙂

@nicolo-ribaudo
Copy link
Contributor Author

I see that Easter is sooner than expected 😛
Thanks a lot!

@SimenB
Copy link
Member

SimenB commented Apr 2, 2021

🐣

@SimenB
Copy link
Member

SimenB commented Apr 2, 2021

@nicolo-ribaudo released in 27.0.0-next.7

@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 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants