[BUG] the different output of run npm run command #6411
Copy link
Copy link
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
the scripts in package is
"scripts": {
"test": "node index.js --PROJECT_ROOT $(pwd)"
},
the index.js file content is
console.warn(process.argv)
i run two command in git bash of win10 os
- npm run test
output
$ npm test
> test-command@1.0.0 test
> node index.js --PROJECT_ROOT $(pwd)
[
'C:\\Program Files\\nodejs\\node.exe',
'D:\\Test\\test-command\\index.js',
'--PROJECT_ROOT',
'$(pwd)'
]
- node index.js --PROJECT_ROOT $(pwd)
output
$ node index.js --PROJECT_ROOT $(pwd)
[
'C:\\Program Files\\nodejs\\node.exe',
'D:\\Test\\test-command\\index.js',
'--PROJECT_ROOT',
'D:/Test/test-command'
]
Expected Behavior
two command output same result as last one
Steps To Reproduce
- create test project
index.js
console.warn(process.argv)
package.json
{
"name": "test-command",
"version": "1.0.0",
"main": "index.js",
"author": "June",
"scripts": {
"test": "node index.js --PROJECT_ROOT $(pwd)"
}
}
- run command
run npm run test
run node index.js --PROJECT_ROOT $(pwd)
you will see the different result
Environment
- npm: 9.6.5
- Node.js: v16.14.2
- OS Name: win10
- System Model Name: dell xps 15
- npm config:
$ npm config ls
; "user" config from C:\Users\june\.npmrc
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v16.14.2
; npm local prefix = D:\Test\test-gitcommand
; npm version = 9.6.5
; cwd = D:\Test\test-command
; HOME = C:\Users\june
; Run `npm config ls -l` to show all defaults.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
v-mragunandhan24 commentedon Jan 20, 2026
@simo-an , I believe this is an issue with the shell environment. The$(pwd) will work in powershell but because npm scripts run in command line terminal, the $ (pwd) is treated as a string literal. To fix this you can instruct npm to use powershell as the script environment.
You can do this by modifying the .npmrc file add
script-shell=powershell. After this when you try to run the test script the output will be identical. If you have any more inputs please fell free to add it, I'm closing this as this is not a bug and is the issue with the environment a script is being executed.