npm / npm/cli

[BUG] `npm.ps1` introduced two regressions

Open
#7,462 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug platform:windows
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

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

npm.ps1 introduced two regressions.

  1. There is an encoding error when the username is non-ascii
  2. When C:\Users\user\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js does not exist, it does not fall back to C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js. Fixed in latest
node:internal/modules/cjs/loader:1205
  throw err;
  ^

Error: Cannot find module 'C:\Users\娴佹槦鏆撮洦\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1202:15)
    at Module._load (node:internal/modules/cjs/loader:1027:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:187:14)
    at node:internal/main/run_main_module:28:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v22.0.0

When I added $OutputEncoding = [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 to fix the encoding issue

PS F:\git\node-js-max_path-windows-bug> npm.ps1
node:internal/modules/cjs/loader:1205
  throw err;
  ^

Error: Cannot find module 'C:\Users\流星暴雨\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1202:15)
    at Module._load (node:internal/modules/cjs/loader:1027:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:187:14)
    at node:internal/main/run_main_module:28:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v22.0.0
Expected Behavior

suceess

Steps To Reproduce
  1. Run npm.ps1 on a Windows machine with a non-ascii username.
  2. See error...
Environment
  • npm: 10.5.1
  • Node.js: v22.0.0
  • OS Name: Windows 11
  • System Model Name:
  • npm config:
; "builtin" config from C:\Program Files\nodejs\node_modules\npm\npmrc

prefix = "C:\\Users\\流星暴雨\\AppData\\Roaming\\npm"

; "global" config from C:\Users\流星暴雨\AppData\Roaming\npm\etc\npmrc

python = "C:\\Python27\\python.exe"

; "user" config from C:\Users\流星暴雨\.npmrc

//registry.npmjs.org/:_authToken = (protected)
strict-ssl = false

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v22.0.0
; npm local prefix = F:\git\node-js-max_path-windows-bug
; npm version = 10.5.1
; cwd = F:\git\node-js-max_path-windows-bug
; HOME = C:\Users\流星暴雨
; Run `npm config ls -l` to show all defaults.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading and running npm.ps1 on Windows with a non-ASCII username, using the reproduction details and environment shown in the issue. Trace how the script passes the npm path and encoding to Node.js; done means npm.ps1 runs successfully without the encoding or missing-module failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, powershell
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.