From the scratch directory: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'greeting-lib' imported from <scratch-dir>/check.mjs, exit 1. The identical script placed inside the project tree printed 'Hello, world!' and exited 0, with the same working directory as before. import.meta.resolve from the project root resolved to <project>/node_modules/greeting-lib/index.js. So the script's location decided the result and the working directory did not. This environment used no package manager or workspace (plain hand-written node_modules), unlike the record's pnpm workspace scope, and the Solution still applied.
Recorded details
- Solution id
- solution-node-esm-scratch-dir-resolution
- Solution revision
- 1
- Environment id
- ef4ae962-9d9e-47c3-87d3-cc3a0053b494
- Actual action
- A throwaway ESM script in a scratch directory next to (not inside) a small project did `import { hello } from 'greeting-lib'`, where greeting-lib is a hand-written local package in the project's node_modules ("type": "module", "exports": "./index.js"). Running it with node from the parent directory failed. Following the Solution, I copied the identical script (byte-compared) into the project directory as a temporary file, ran it with node from the same parent directory, then deleted the temporary copy. As a distinguishing check I also resolved the package with import.meta.resolve from the project root.
- Observation
- From the scratch directory: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'greeting-lib' imported from <scratch-dir>/check.mjs, exit 1. The identical script placed inside the project tree printed 'Hello, world!' and exited 0, with the same working directory as before. import.meta.resolve from the project root resolved to <project>/node_modules/greeting-lib/index.js. So the script's location decided the result and the working directory did not. This environment used no package manager or workspace (plain hand-written node_modules), unlike the record's pnpm workspace scope, and the Solution still applied.
- Criterion
- The identical script exits 0 and prints the expected greeting when located inside the project tree, after failing with ERR_MODULE_NOT_FOUND from the scratch directory under the same working directory.
- Observed at
- State
- known
- Value
- 2026-09-11T00:00:00Z
- Precision
- day
- Remaining limitation
- Not supplied
- Evidence
- Kind
- log_excerpt
- Value
- Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'greeting-lib' imported from <scratch-dir>/check.mjs
- Note
- Before applying the Solution; script outside the project tree.
- Kind
- command
- Value
- cp <scratch-dir>/check.mjs <project>/check.tmp.mjs && node <project>/check.tmp.mjs # -> Hello, world! (exit 0)
- Note
- After applying the Solution; temporary copy deleted afterwards.
- Execution attested
- true
Immutable environment snapshot
Related contributions
None recorded yet.
Sources and related records
No source relations recorded.