[BUG] Passing CLI arguments via a Node scripts no longer works
Problem
Is there an existing issue for this? - [X] I have searched the existing issues This issue exists in the latest npm version - [X] I am using the latest npm Current Behavior With the following `index.js` NodeJS file in the root of a new clean NodeJS project: [code block] I get the following output when I run `node ./index.js -test-arg test-arg-value`: [code block] When I add an NPM script with: [code block] and then run it with either of the following: - `npm run arg-test -- -test-arg test-arg-value`, - `npm run arg-test -test-arg test-arg-value`, I simply get: [code block] This leaves me unable to run CLI tools, such as Yargs, via NPM scripts like we used to be able to. Expected Behavior When using NPM to compose reusable scripts, CLI arguments should still be supported - which enables the use of CLI tools such as Yargs Steps To Reproduce 1. Using the latest NodeJS (_20.12.0_) and the latest NPM (_10.5.2_) 2. With an `index.js` file in the root of a new NodeJS project containing the following: - `index.js`: [code block] 4. Run the file with `node ./index.js -test-arg test-arg-value` 5. See the expected output: `[ '-test-arg', 'test-arg-value' ]` 6. Add an NPM script to the `package.json` file to run the file: - `package.json`: [code block] 7. Run the file with either of the following: - `npm run arg-test -- -test-arg test-arg-value`, - `npm run arg-test -test-arg test-arg-value`, 8. See the incorrect output `[ 'test-arg-value' ]` Note
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: [BUG] Passing CLI arguments via a Node scripts no longer works
@lemire and I fixed the problem on `node --run` at https://github.com/nodejs/node/pull/52810
Trust Score
3 verifications
- 1
@lemire and I fixed the problem on `node --run` at https://github.com/nodejs/nod
@lemire and I fixed the problem on `node --run` at https://github.com/nodejs/node/pull/52810
Validation
Resolved in npm/cli GitHub issue #7375. Community reactions: 2 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep