`require.resolve` regression starts from Node v12 with `paths`
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 122k
- Fork
- 37.3k
- Merge medio
- 4g 2h
- PR unite (30g)
- 283
Descrizione
Version
v20.19.2
Platform
Darwin MacBookPro 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000 arm64
Subsystem
No response
What steps will reproduce the bug?
https://github.com/JounQin/test/tree/repro/node_require_resolve_paths
Simply run node test.js
On node 10:
`resolve` npm package: <CWD>/fixtures/bar.js
`require.resolve` built-in function: <CWD>/fixtures/bar.js
How often does it reproduce? Is there a required condition?
Persist
What is the expected behavior? Why is that the expected behavior?
There is a related old issue #29139.
What do you see instead?
On node 12+, of course including Node LTS (20+)
`resolve` npm package: /Users/JounQin/Workspaces/GitHub/test/fixtures/bar.js
node:internal/modules/cjs/loader:1404
throw err;
^
Error: Cannot find module 'bar'
Require stack:
- <CWD>/test.js
at Function._resolveFilename (node:internal/modules/cjs/loader:1401:15)
at Function.resolve (node:internal/modules/helpers:145:19)
at Object.<anonymous> (/Users/JounQin/Workspaces/GitHub/test/test.js:16:11)
at Module._compile (node:internal/modules/cjs/loader:1730:14)
at Object..js (node:internal/modules/cjs/loader:1895:10)
at Module.load (node:internal/modules/cjs/loader:1465:32)
at Function._load (node:internal/modules/cjs/loader:1282:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '<CWD>/test.js' ]
}
Additional information
I believe there is no reports because most projects use http://npmjs.com/resolve instead, and it behaviors same as Node 10-, and I'm trying to remove resolve as dependency, so I just met this issue at https://github.com/un-ts/eslint-plugin-import-x/pull/272#issuecomment-2915145320
cc @cjihrig
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Esegui il test.js della riproduzione collegata con Node 10 e Node 12+ e confronta i risultati di require.resolve quando viene fornito paths. Leggi il percorso del loader CommonJS mostrato nello stack trace e l’issue correlata #29139; il lavoro è completato quando la riproduzione risolve fixtures/bar.js in modo coerente senza il pacchetto esterno resolve.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, node.js
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100