Skip to content

[BUG] script-shell setting not respected in prepublishOnly #9477

@wiggisser

Description

@wiggisser

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

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

  1. on a windows system make a bash.exe available (for instance install git for windows)
  2. set script-shell="c:\program files\git\bin\bash.exe" (or whereever bash.exe is located) in your global .npmrc
  3. 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"
  },
}
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next steps

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions