createRequire does not respect deleting module from require.cache
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
Version
v23.10.0
Platform
Microsoft Windows NT 10.0.26100.0 x64
Subsystem
No response
What steps will reproduce the bug?
mod.js
console.log('in mod.ts')
testcase.js
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
require('./mod.js?1')
const key = Object.keys(require.cache)[0]
delete require.cache[key]
require('./mod.js?2')
How often does it reproduce? Is there a required condition?
Every time.
What is the expected behavior? Why is that the expected behavior?
in mod.ts
in mod.ts
What do you see instead?
in mod.ts
Additional information
I traced it to this line, which just fully ignores source.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with testcase.js and mod.js from the reproduction, then inspect lib/internal/modules/esm/loader.js around lines 390-391, where the report says source is ignored. Run the testcase on Windows or a comparable Node.js environment and trace how deleting require.cache affects the second query. Done means the expected message appears twice.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100