Skip to content

[BUG] the different output of run npm run command #6411

Closed

Description

@simo-an

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

  1. 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)'
]
  1. 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

  1. 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)"
  }
}

  1. 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.

Activity

  1. added
    Bugthing that needs fixing
    Needs Triageneeds review for next steps
    Release 9.xwork is associated with a specific npm 9 release
    on May 1, 2023
  2. v-mragunandhan24 commented on Jan 20, 2026

    @v-mragunandhan24

    @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.

  3. removed
    Bugthing that needs fixing
    Needs Triageneeds review for next steps
    Release 9.xwork is associated with a specific npm 9 release
    on Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions