Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
AddictArts opened this issue Aug 13, 2024 · 5 comments · May be fixed by #7725
Open
2 tasks done

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

AddictArts opened this issue Aug 13, 2024 · 5 comments · May be fixed by #7725
Labels
Bug thing that needs fixing Needs Triage needs review for next steps platform:windows is Windows-specific

Comments

@AddictArts
Copy link

AddictArts commented Aug 13, 2024

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

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
@nipunn1313
Copy link

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.

@shadowspawn
Copy link
Contributor

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

@nipunn1313
Copy link

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
Copy link

Can repro from CMD, Git Bash, Powershell

npm clean-install --prefix scripts works fine.

nipunn1313 added a commit to nipunn1313/npm-cli that referenced this issue Aug 15, 2024
I found that globalDir/localDir and globalPrefix/localPrefix
end up being the same value when `--prefix` is set. This was
surprising to me, but it does appear that `globalPrefix` is set
to match `prefix` at the end of loading.

This means that the globalTop logic is actually incorrect here.
It accidentally worked on non-windows machines.

For example if running `npm i --prefix scripts`

On non-windows
this.npm.globalDir = $CWD/scripts/lib/node_modules

On windows
this.npm.globalDir = $CWD/scripts/node_modules

IMHO, the logic inside of npmconfig is also incorrect here, since
globalDir is being set to this bogus `$CWD/scripts/lib/node_modules`

However, this fix should work regardless - since it stops relying
on the specific values of globalDir.

Fixes npm#7722

I manually tested `npm install` and `npm install --prefix` on both
windows and mac. Everything works now.
@nipunn1313 nipunn1313 linked a pull request Aug 15, 2024 that will close this issue
@nipunn1313
Copy link

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

@milaninfy milaninfy added the platform:windows is Windows-specific label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps platform:windows is Windows-specific
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants