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() shouldn't be cached when the required files throws #11259

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

require() shouldn't be cached when the required files throws #11259

nicolo-ribaudo opened this issue Apr 1, 2021 · 2 comments · Fixed by #11263

Comments

@nicolo-ribaudo
Copy link
Contributor

🐛 Bug Report

If a CJS file that throws is requried twice, the second time Jest doesn't throw but returns a cached result.

To Reproduce

See repo below

Expected behavior

Jest should throw both times, but the second time it returns the module.exports object defined by the requried module before throwing.

Link to repl or repo (highly encouraged)

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

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 

Context

I found this while trying to work around #11258, but it's not related to ESM.

@SimenB
Copy link
Member

SimenB commented Apr 1, 2021

Oh, interesting! It's been that way for years and years 😃 Should be pretty straightforward to fix, tho (just removing the module from the cache in a catch then rethrowing

@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 Jun 20, 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