-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
Description
Version
v22.18.0
Platform
Darwin 23.5.0 arm64 (macOS 14.5 on Apple M2)
Subsystem
modules / esm‑loader
What steps will reproduce the bug?
Below is the smallest command‑line recipe I know that shows the crash without creating any source files.
It works by trying to require() a pure ES‑module that lives in node_modules (the chalk package from npm).
Because chalk@5 ships only ES‑module code, the call goes through Node’s internal importSyncForRequire() → ModuleLoader.getModuleJobForRequire() path and triggers the missing null‑check that was introduced in commit
See comments below
How often does it reproduce? Is there a required condition?
Reproduces 100 % of the time on v22.18.0 (arm64 & x64, macOS & Linux).
Does not reproduce on v22.17.0 or earlier.
What is the expected behavior? Why is that the expected behavior?
Program exits silently (because the required module is empty).
What do you see instead?
TypeError: Cannot read properties of undefined (reading 'getStatus')
at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:463:22)
at new ModuleJobSync (node: internal/modules/esm/module_job: 393:34)
at ModuleLoader. importSyncForRequire (node:internal/modules/esm/loader:426:11)
at loadESMFromCJS (node: internal/modules/cjs/loader:1519:24) at Module._compile (node: internal/modules/cjs/loader:1670:5)
at node: internal/modules/cjs/loader: 1820:10
at Object.newLoader (./node_modules/esbuild-register/dist/node.js:2262:9) at extensions.. js (./node_modules/esbuild-register/dist/node.js:4838:24)
at Module.load (node:internal/modules/cjs/loader:1423:32)
at Function._load (node: internal/modules/cjs/loader:1246:12)
• Would you like to help improve Storybook by sending anonymous crash reports? ... yes error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Process finished with exit code 1
Additional information
Regression introduced by commit 42c4ca6024 (“syncify default path of ModuleLoader.load”).
The commit changed ModuleLoader.load() from async to synchronous, so
moduleMap.get(specifier) can now return undefined in
getModuleJobForRequire(), which then dereferences .getStatus().
A one‑line null guard should fix the crash.