Closed
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
With the following index.js
NodeJS file in the root of a new clean NodeJS project:
console.log(process.argv.slice(2));
I get the following output when I run node ./index.js -test-arg test-arg-value
:
[ '-test-arg', 'test-arg-value' ]
When I add an NPM script with:
...
"scripts": {
"arg-test": "node ./index.js",
...
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:
[ 'test-arg-value' ]
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
- Using the latest NodeJS (20.12.0) and the latest NPM (10.5.2)
- With an
index.js
file in the root of a new NodeJS project containing the following:index.js
:console.log(process.argv.slice(2));
- Run the file with
node ./index.js -test-arg test-arg-value
- See the expected output:
[ '-test-arg', 'test-arg-value' ]
- Add an NPM script to the
package.json
file to run the file:package.json
:"type": "module", "scripts": { "arg-test": "node ./index.js" }
- 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
,
- See the incorrect output
[ 'test-arg-value' ]
Notes:
- I'm using module type Node with
"type": "module",
in thepackage.json
file. - I've tried with Bash terminal but did not experience this issues. Only PowerShell and Command had this error.
Environment
- npm: 10.5.2
- Node.js: 20.12.0
- OS Name: Windows 11 Pro 23H2 (22631.3447)
- System Model Name: Dell G15 5510
- npm config:
; "user" config from C:\Users\jp.strydom\.npmrc
//registry.npmjs.org/:_authToken = (protected)
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v20.12.0
; npm local prefix = C:\Data\Development\XXX\XXX
; npm version = 10.5.2
; cwd = C:\Data\Development\XXX\XXX
; HOME = C:\Users\XXX
; Run `npm config ls -l` to show all defaults.