Closed
Description
Bug Report Checklist
- I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
- I have searched for related issues and issues with the
faq
label, but none matched my issue. - 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.
- I want to provide a PR to resolve this
Expected
npm run test
to output:
Works fine
√ ESM TypeScript Test
1 passing (2ms)
Actual
npm run test
now results in:
Exception during run: Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\Borewit\IdeaProjects\mocha-esm-issue\index.js' imported from C:\Users\Borewit\IdeaProjects\mocha-esm-issue\test.ts
at finalizeResolution (node:internal/modules/esm/resolve:275:11)
at moduleResolve (node:internal/modules/esm/resolve:932:10)
at defaultResolve (node:internal/modules/esm/resolve:1056:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:654:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:603:25)
at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:353:53)
at new ModuleJobSync (node:internal/modules/esm/module_job:341:34)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:326:11)
at loadESMFromCJS (node:internal/modules/cjs/loader:1411:24)
at Module._compile (node:internal/modules/cjs/loader:1544:5)
at Object..js (node:internal/modules/cjs/loader:1699:10)
at Module.load (node:internal/modules/cjs/loader:1313:32)
at Function._load (node:internal/modules/cjs/loader:1123:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
at Module.require (node:internal/modules/cjs/loader:1335:12)
at require (node:internal/modules/helpers:136:16)
at Object.requireModule [as requireOrImport] (C:\Users\Borewit\IdeaProjects\mocha-esm-issue\node_modules\mocha\lib\nodejs\esm-utils.js:94:12)
at exports.loadFilesAsync (C:\Users\Borewit\IdeaProjects\mocha-esm-issue\node_modules\mocha\lib\nodejs\esm-utils.js:128:34)
at Mocha.loadFilesAsync (C:\Users\Borewit\IdeaProjects\mocha-esm-issue\node_modules\mocha\lib\mocha.js:451:19)
at singleRun (C:\Users\Borewit\IdeaProjects\mocha-esm-issue\node_modules\mocha\lib\cli\run-helpers.js:164:15)
at exports.runMocha (C:\Users\Borewit\IdeaProjects\mocha-esm-issue\node_modules\mocha\lib\cli\run-helpers.js:241:10)
at exports.handler (C:\Users\Borewit\IdeaProjects\mocha-esm-issue\node_modules\mocha\lib\cli\run.js:379:11)
at C:\Users\Borewit\IdeaProjects\mocha-esm-issue\node_modules\yargs\build\index.cjs:1:8993
at C:\Users\Borewit\IdeaProjects\mocha-esm-issue\node_modules\yargs\build\index.cjs:1:4949 {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///C:/Users/Borewit/IdeaProjects/mocha-esm-issue/index.js'
}
Minimal, Reproducible Example
Original regression exposing the issue can be found here: Borewit/music-metadata#2435
I created an Minimum Reproducible Example here: https://github.com/Borewit/mocha-esm-issue
Run
npm install
npm run test
Versions
Updating from Mocha version v11.6.0 to v11.7.0
Additional Info
I suspect this issue was introduced in PR #5366.
Issues is not present in Node version ≥ 22.15.0. It is reproducable with 22.14.0 and older.