cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] `npm exec` on Windows may fail depending on the shell codepage

Open yhatt opened this issue 3 years ago • 0 comments

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

In npm v8.13.0 and earlier versions, npm exec may fail if executed in the Windows shell that have non-standard code page. I've received a feedback from the user of my Node tool who tried to use via npx: marp-team/marp-cli#465

Expected Behavior

npm exec should pass correct arguments to the command regardless of the shell codebase.

npm v8.12.2 and earlier versions had worked as that.

Steps To Reproduce

  1. Open cmd.exe.
  2. Run chcp 65001, to change the active code page of the current shell into UTF-8.
  3. Run npm exec echo-cli ö.
  4. See error...
> chcp 65001
Active code page: 65001

> npm exec echo-cli ö
'cho-cli' is not recognized as an internal or external command,
operable program or batch file.

This error can when using npm v8.13.0 and later. npm exec is working in v8.12.x correctly.

> npm install -g [email protected]
> npm -v
8.12.2

> chcp 65001
> npm exec echo-cli ö
ö

Environment

  • npm: 8.15.1
  • Node.js: 18.7.0
  • OS Name: Windows 10 (10.0.19041 Build 19041)
  • System Model Name: Virtual Machine (Windows Sandbox)
  • npm config:
; "builtin" config from C:\Users\WDAGUtilityAccount\AppData\Roaming\npm\node_modules\npm\npmrc

prefix = "C:\\Users\\WDAGUtilityAccount\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v18.7.0
; npm local prefix = C:\Users\WDAGUtilityAccount
; npm version = 8.15.1
; cwd = C:\Users\WDAGUtilityAccount
; HOME = C:\Users\WDAGUtilityAccount
; Run `npm config ls -l` to show all defaults.

yhatt avatar Jul 30 '22 07:07 yhatt