`require.cache` is `undefined` in SEA
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
Version
v20.4.0 v20.5.1 v20.3.0
Platform
Linux 5.15.90.1-microsoft-standard-WSL2
Subsystem
No response
What steps will reproduce the bug?
echo 'console.log(typeof require.cache)' > main.js
node main.js
echo '{ "main": "main.js", "output": "sea-prep.blob" }' > sea-config.json
node --experimental-sea-config sea-config.json
cp $(command -v node) hello
npx postject hello NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
./hello
How often does it reproduce? Is there a required condition?
Always reproducible
What is the expected behavior? Why is that the expected behavior?
require.cache should be an object as of https://nodejs.org/api/modules.html#requirecache
What do you see instead?
require.cache is undefined. Trying to index it or enumerate it with Object.entries will result in TypeError
Additional information
This is relevant for Fastify which uses cache to provide a printable name for a plugin (based on its file path). See https://github.com/fastify/fastify/blob/c235d2dc136a67c51095f188742c743d8cb32839/lib/pluginUtils.js#L27
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先在 main.js 中进行复现,并使用 sea-config.json 完成 SEA 设置,然后比较普通 Node 进程和生成的可执行文件中的 require.cache 行为。阅读 Node.js 模块文档和与 SEA 相关的运行时入口点;当在复现的 SEA 场景中 require.cache 是一个对象且不破坏 Fastify pluginUtils 用例时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, nodejs
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100