cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] Windows npm install --prefix errors and looks for the package.json in the cwd

Open AddictArts opened this issue 1 year ago • 5 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

Errors saying it cannot find package.json

Expected Behavior

Install packages to the directory where the prefix is and package.json.

Steps To Reproduce

1, Use Windows 11 2. Use Node 18, 20, 22 ... 3. Use latest npm 4. Try an install with --prefix

In this repo https://github.com/get-convex/convex-backend, which has a scripts subfolder.

error

D:\box\rust\convex-backend>npm install --prefix scripts
npm error code ENOENT
npm error syscall open
npm error path D:\box\rust\convex-backend\package.json

Environment

  • npm: 9.8.1
  • Node.js: 18.18.0
  • OS Name: Windows
; node version = v18.18.0
; npm local prefix = D:\box\rust\convex-backend
; npm version = 9.8.1
; cwd = D:\box\rust\convex-backend

AddictArts avatar Aug 13 '24 23:08 AddictArts

There are a couple of workarounds to this bug for those who are blocked by this.

cd scripts
npm install

and

npm ci --prefix scripts

Neither of those versions of the incantation appear to be affected by this bug.

nipunn1313 avatar Aug 14 '24 00:08 nipunn1313

(I was not able reproduce this problem on macOS with npm 10.2.4 or npm 10.8.2.)

shadowspawn avatar Aug 15 '24 06:08 shadowspawn

image

$ cat  'C:\Users\nipunn\AppData\Local\npm-cache\_logs\2024-08-15T07_24_46_615Z-debug-0.log'
0 verbose cli C:\Program Files (x86)\nodejs\node.exe C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js
1 info using [email protected]
2 info using [email protected]
3 silly config load:file:C:\ProgramData\nvm\v18.17.0\node_modules\npm\npmrc
4 silly config load:file:C:\Users\nipunn\src\convex-backend\scripts\.npmrc
5 silly config load:file:C:\Users\nipunn\.npmrc
6 silly config load:file:C:\Users\nipunn\src\convex-backend\scripts\etc\npmrc
7 verbose title npm install
8 verbose argv "install" "--prefix" "scripts"
9 verbose logfile logs-max:10 dir:C:\Users\nipunn\AppData\Local\npm-cache\_logs\2024-08-15T07_24_46_615Z-
10 verbose logfile C:\Users\nipunn\AppData\Local\npm-cache\_logs\2024-08-15T07_24_46_615Z-debug-0.log
11 silly packumentCache heap:4345298944 maxSize:1086324736 maxEntrySize:543162368
12 silly logfile start cleaning logs, removing 1 files
13 silly logfile done cleaning log files
14 verbose stack Error: Could not read package.json: Error: ENOENT: no such file or directory, open 'C:\Users\nipunn\src\convex-backend\package.json'
15 error code ENOENT
16 error syscall open
17 error path C:\Users\nipunn\src\convex-backend\package.json
18 error errno -4058
19 error enoent Could not read package.json: Error: ENOENT: no such file or directory, open 'C:\Users\nipunn\src\convex-backend\package.json'
20 error enoent This is related to npm not being able to find a file.
20 error enoent
21 silly unfinished npm timer reify 1723706687337
22 silly unfinished npm timer reify:loadTrees 1723706687344
23 silly unfinished npm timer idealTree:userRequests 1723706688431
24 verbose cwd C:\Users\nipunn\src\convex-backend
25 verbose os Windows_NT 10.0.22000
26 verbose node v18.17.0
27 verbose npm  v10.8.2
28 verbose exit -4058
29 verbose code -4058
30 error A complete log of this run can be found in: C:\Users\nipunn\AppData\Local\npm-cache\_logs\2024-08-15T07_24_46_615Z-debug-0.log

nipunn1313 avatar Aug 15 '24 07:08 nipunn1313

Can repro from CMD, Git Bash, Powershell

npm clean-install --prefix scripts works fine.

nipunn1313 avatar Aug 15 '24 07:08 nipunn1313

I spent a couple hours looking into this since I have the repro. Got a fix here #7725

nipunn1313 avatar Aug 15 '24 09:08 nipunn1313

Closing This is similer if not duplicate of https://github.com/npm/cli/issues/4511

milaninfy avatar Oct 03 '24 19:10 milaninfy