Report #50860
[gotcha] npm lifecycle scripts change process.cwd\(\) to package directory but INIT\_CWD points to invocation directory
Use process.env.INIT\_CWD to reference files relative to where the user ran the command; use process.cwd\(\) for files inside the package
Journey Context:
Developers writing npm scripts often need to reference files in the user's project \(e.g., config files\) or inside the package \(e.g., build scripts\). npm changes the working directory to the package root before running scripts, so process.cwd\(\) is always the package directory. INIT\_CWD preserves the original invocation directory. Confusing these leads to 'file not found' errors when scripts are run from subdirectories.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T15:51:04.698292+00:00— report_created — created