Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
I'm on a windows system and use script-shell=c:\program files\git\bin\bash.exe in my global .npmrc.
In one of my projects I have the following script section
"scripts": {
"build:src": "rm -rf dist && tsc",
"prepublishOnly": "rm -rf somefolder",
...
}
calling rm works fine when I do npm run build:src, but it fails with the following error when I do npm publish
'rm' is not recognized as an internal or external command,
operable program or batch file.
npm error code 1
npm error path C:\tmp\rmtest
npm error command failed
npm error command C:\WINDOWS\system32\cmd.exe /d /s /c rm -rf somefolder && npm run build
First I thought it had something to do with prepublishOnly being a known hook, that is called by npm under certain conditions, whereas build:src is explictly called via npm run. But that explanaition didn't hold, because if I add "prepack": "rm -rf somefolder" instead of prepublishOnly" and then do npm packit also works fine andsomefolder` is removed ... Did not test for any other predefined hooks ...
Yeah I know I can easily work around this by moving the rm ... into another script and call this script in the prepublishOnly hook. I was just surprised for this to fail, because this is an older project I haven't touched for quite a while and this used to work with an older version of npm (otherwise I probably would have checked it in that way)
Expected Behavior
Commands available in the defined script shell should be available in all hooks. Ie in this special case rm -rf somefolder should work in all hooks
Steps To Reproduce
- on a windows system make a
bash.exe available (for instance install git for windows)
- set
script-shell="c:\program files\git\bin\bash.exe" (or whereever bash.exe is located) in your global .npmrc
- in an empty directory create a simple package.json
{
"name": "rmtest",
"version": "1.0.0",
"scripts": {
"prepublishOnly": "rm -rf somefolder",
"build:src": "rm -rf dist && tsc"
},
}
- in that directory call
npm publish
Environment
- npm: 11.16.0
- Node.js: 22.20.0
- OS Name: Win11 Pro
- System Model Name:
- npm config:
//... some scopes and authentications removed ...
script-shell = "c:\\Program Files\\Git\\bin\\bash.exe"
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v22.20.0
; npm local prefix = C:\tmp\rmtest
; npm version = 11.16.0
; cwd = C:\tmp\rmtest
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
I'm on a windows system and use
script-shell=c:\program files\git\bin\bash.exein my global.npmrc.In one of my projects I have the following script section
calling
rmworks fine when I donpm run build:src, but it fails with the following error when I donpm publishFirst I thought it had something to do with
prepublishOnlybeing a known hook, that is called bynpmunder certain conditions, whereasbuild:srcis explictly called vianpm run. But that explanaition didn't hold, because if I add"prepack": "rm -rf somefolder"instead ofprepublishOnly" and then donpm packit also works fine andsomefolder` is removed ... Did not test for any other predefined hooks ...Yeah I know I can easily work around this by moving the
rm ...into another script and call this script in theprepublishOnlyhook. I was just surprised for this to fail, because this is an older project I haven't touched for quite a while and this used to work with an older version of npm (otherwise I probably would have checked it in that way)Expected Behavior
Commands available in the defined script shell should be available in all hooks. Ie in this special case
rm -rf somefoldershould work in all hooksSteps To Reproduce
bash.exeavailable (for instance install git for windows)script-shell="c:\program files\git\bin\bash.exe"(or whereeverbash.exeis located) in your global .npmrcnpm publishEnvironment