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
#7490 introduces "cleaning" of workspaces during npm ci
on root package however it also wipes the workspace node_modules incorrectly since they are not re-installed anywhere. #7490 (comment)
TS compilations need those modules. This should be considered with more thought. It's now doing the clean part yes but it's not doing the install part on clean-install i.e. install the node_modules for the workspaces since this isn't how the npm i --workspaces=true
e.g. works (they just link the workspace etc maybe there's room to improve too).
Now you cannot run a workspace script that calls a binary after the clean-install which you surely can if you just use install here. If you do a clean-install on the workspace it has the binary, after which you do a clean-install on the root it for some reason wipes the workspace's packages.
You can test my issue of having let say copyfiles package on postinstall for a workspace module. Interestingly postinstall scripts are indeed run for workspaces but modules don't get re-installed and thus don't exist anywhere.
And you should get following when running npm ci for the parent module:
npm error sh: 1: copyfiles: not found
while workspace package.json looks something like:
"scripts": {
"postinstall": "copyfiles . .",
},
"dependencies": {
"copyfiles": "^2.4.1",
this shouldn't happen since the workspace module is installed earlier... But now npm ci breaks it.
Bad example but to illustrate our workflow. Also to mention the file structure is ../workspace
so the workspace isn't inside the service which might affect binary usage too.
Expected Behavior
Earlier behavior before 10.8.1: i.e. if the workspace has node_modules it should be left as it to allow building succeed.
Or by default install workspace modules too. Or only explicitly when given --workspaces=true
. How about --workspaces=false
should it not disable any of this?
Steps To Reproduce
Environment
- npm: 10.8.1
- Node.js: 20.15.0