🐛 Bug: deep requires without a file extension broke in 12.0.0-rc.5
type: bugstatus: in triage
### Bug Report Checklist
- [x] This is NOT a [security, `npm audit`, or GitHub Advisory issue](https://mochajs.org/explainers/security-vulnerability-reports).
- [x] I have read and agree to Mocha's [Code of Conduct](https://github.com/mochajs/mocha/blob/main/.github/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/mochajs/mocha/blob/main/.github/CONTRIBUTING.md)
- [x] I have searched for [related issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue) and [issues with the `faq` label](https://github.com/mochajs/mocha/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3Afaq%20), but none matched my issue.
- [x] I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
- [x] I want to provide a PR to resolve this
### Expected
`require('mocha/lib/reporters/base')` keeps resolving in 12.0.0-rc.5 like it did in rc.4 and in 11.x.
### Actual
It throws `Cannot find module`. The `exports` map that was added in #6168 turns off CommonJS extension search for subpaths so `./lib/reporters/base` maps to a literal file that doesnt exist. Same goes for `mocha/lib/stats-collector` and `mocha/lib/errors` and `mocha/lib/suite` and `mocha/index` and `mocha/bin/mocha` and any other deep path written without a extension.
### Minimal, Complete and Verifiable Example
Create a new folder and:
1. `npm init -y`
2. `npm i mocha@12.0.0-rc.4`
3. `node -e "require.resolve('mocha/lib/reporters/base')"` # Should be just fine
<img width="2394" height="724" alt="A screenshot showing no returned Cannot find module error" src="https://github.com/user-attachments/assets/15725f40-9024-402a-816c-831300990115" />
then:
`npm i mocha@12.0.0-rc.5`
`node -e "require.resolve('mocha/lib/reporters/base')" # Cannot find module`
<img width="2495" height="1233" alt="A screenshot showing a returned Cannot find module error" src="https://github.com/user-attachments/assets/0d769922-6f97-45b2-8b2c-d4925364260c" />
rc.4 and rc.5 have the same files, exports is the only package.json difference, so that isolates it.
### Versions
mocha 12.0.0-rc.5 (broken), 12.0.0-rc.4 and 11.7.6 (fine)
node 24.17.0. Not platform specific.
### Additional Info
_No response_
8 条评论