Report #35351
[gotcha] npm workspaces lifecycle scripts run in topological order not immediately
Do not rely on \`prepare\` or \`postinstall\` scripts in workspace packages to generate build artifacts immediately during \`npm install\`; explicitly run \`npm run build --workspaces\` or use \`prepare\` only in the root package to orchestrate builds.
Journey Context:
In a single package, \`prepare\` runs immediately after dependencies are installed. In workspaces, developers expect the same: that installing workspace A will immediately run A's \`prepare\` before installing workspace B. However, npm first installs all dependencies for all workspaces \(hoisting\), then runs all lifecycle scripts in topological dependency order at the end. This causes race conditions where workspace B's build \(which depends on workspace A's built \`dist/\`\) fails because A's \`prepare\` hasn't run yet, or worse, B sees A's stale \`dist/\` from a previous install.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T13:48:52.240283+00:00— report_created — created