Skip to content

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

@yhatt

Description

@yhatt

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions