[BUG] postinstall in a package consumed as a workspace in a monorepo throws a "command not found" error when running `npm ci`
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.1k
- Forks
- 4.7k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 19
Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
When using npm workspaces, if a package (called consumer in my example) consumes another package (called consumed) as a workspace and THAT package uses a postinstall script that calls a third package (called topostinstall) then when you run npm ci on the first package (consumer) it will throw an error when it gets to the postinstall:
npm error code 127
npm error path /Users/bryce/Documents/LLK/experiments/workspacePostinstallReproduction/packages/consumed
npm error command failed
npm error command sh -c topostinstall
npm error sh: topostinstall: command not found
npm error A complete log of this run can be found in: /Users/bryce/.npm/_logs/2025-07-18T18_13_25_324Z-debug-0.log
Expected Behavior
running npm ci from packages/consumer installs the "consumed" package and successfully runs the postinstall command without errors.
This is similar to this issue https://github.com/npm/cli/issues/7692 which was closed without repro steps.
Steps To Reproduce
I created a simplified case of this in this repository: https://github.com/BryceLTaylor/workspacePostinstallReproduction
You can clone that repository and then
- cd into packages/consumer
- run
npm ci
You should see that error.
However, if you instead:
- cd into packages/consumed
- run
npm ciORnpm install - cd into packages/consumer
- run
npm install
You will not get the error.
The README in that repo contains more context
Environment
- npm: 11.4.2
- Node.js: v22.17.0
- OS Name: macOS
- System Model Name:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Clone the linked workspacePostinstallReproduction repository, enter packages/consumer, and run npm ci to reproduce the missing topostinstall command. Then trace npm CLI handling for workspace installation and lifecycle scripts; done means the consumer install completes and the consumed package's postinstall command resolves successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100