nodejs / nodejs/node

`require.cache` is `undefined` in SEA

Open
#49,163 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

single-executable stale
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

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

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 the reproduction in main.js and the SEA setup using sea-config.json, then compare require.cache behavior in a regular Node process and the generated executable. Read the Node.js modules documentation and the SEA-related runtime entry points; done means require.cache is an object in the reproduced SEA case without breaking the Fastify pluginUtils use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.