nodejs / nodejs/node

createRequire does not respect deleting module from require.cache

Open
#57,696 16 comments 0 reactions 0 assignees View on GitHub

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.

https://github.com/nodejs/node/blob/eab0fe264bf5e7e105827651bbb6a895354aa9c3/lib/internal/modules/esm/loader.js#L390-L391

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.