nodejs / nodejs/node

createRequire does not respect deleting module from require.cache

未关闭
#57,696 16 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从复现中的 testcase.js 和 mod.js 开始,然后检查 lib/internal/modules/esm/loader.js 第 390-391 行附近,报告指出 source 在此处被忽略。在 Windows 或兼容的 Node.js 环境中运行 testcase,并跟踪删除 require.cache 如何影响第二次查询。预期消息出现两次即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
描述清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。