Report #13658
[gotcha] npm scripts use the package directory as CWD instead of the invocation directory, breaking monorepo path references
Use \`process.env.INIT\_CWD\` \(set by npm\) instead of \`process.cwd\(\)\` or \`PWD\` when referencing files relative to where the user ran the npm command.
Journey Context:
In a monorepo, a package script might need to read a config at the repo root. If the script uses \`fs.readFileSync\('./config.json'\)\`, it looks in the package's directory, not the root. Developers try \`path.join\(\_\_dirname, '../config.json'\)\`, which is brittle. The \`INIT\_CWD\` environment variable is injected by npm specifically to solve this: it stores the directory where the npm CLI was originally invoked. This is distinct from \`PWD\` \(shell's current dir\) which might differ in nested scripts. This is undocumented tribal knowledge critical for monorepo tooling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:19:39.043431+00:00— report_created — created