npm / npm/cli

[BUG] Since 8.17.0 running post/pre scripts fails on shells that are not bash-like

Open
#5,489 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 8.x
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 a package.json contains something like

"postinstall": "node -e \"console.log('Hello World')\""

npm install is going to fail with

npm ERR! command sh -c -- node -e "console.log('Hello World')"
npm ERR! node -e "console.log('Hello World')": --: not found

I believe that's because run-script was updated in 8.17.0 and it now includes this line, which was added in this commit. -- isn't a valid argument for a number of shells that are not bash compatible.

In turn this breaks CI/CD builds on some systems. See https://github.com/yarnpkg/yarn/issues/8866 and https://github.com/npm/run-script/issues/103.

Expected Behavior

I expect to be able to use npm in whichever shell I choose.

Steps To Reproduce

Described above.

Environment
  • npm: 8.19.1
  • Node.js: v16.16.0
  • OS Name: FreeBSD

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with node_modules/@npmcli/run-script/lib/make-spawn-args.js at the linked line and compare the related npm/run-script references. Reproduce the package.json postinstall example on FreeBSD or another non-bash-like shell; done means npm install runs the script successfully without breaking supported shell behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, shell
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.