Open maxmag-soft opened 2 years ago
This --prefix worked back in NPM 8.1.2 in Windows and Linux Now, they don't Tested on ArchLinux npm 8.5.2
i'm not following what's happening here.. i would note that --cwd
isn't a config flag with any meaning in npm>=7
can you tell us more about your directory structure and what you're trying to do? are you using workspaces?
Hi nlf, I have a git repo in /home/user/dev/myrepo/ inside I have a next.js project in /home/user/dev/myrepo/arcadia/ I wanted to run npm commands install/build/dev/etc while I am at the repo folder, not inside my project folder (the package.json folder) no, its not a workspace
βββ my_repo
β βββ arcadia
β β βββ package.json
β β βββ next.config.js
β β βββ node_modules
my workaround is this: downloading node and npm from official site and changing path variable. export PATH="$PWD/nodejs/node-v16.13.2-linux-x64/bin:$PATH" npm --prefix $PWD/arcadia install npm --version 8.1.2 node --version v16.13.2
i was able to reproduce this following these steps, please let me know if i missed anything:
> mkdir repo_root
> cd repo_root
> git init
> mkdir project
> cd project
> npm init -y
# installing a dependency in the project just so we can see it's doing something
> npm i debug
> cd ..
> npm --prefix ./project install
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\username\Projects\temp\root/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\username\Projects\temp\root\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
which sure makes it look as though we're disregarding the --prefix
parameter entirely. it's worth noting, the same series of commands run in osx and linux works correctly, however attempts in bash, cmd, and powershell all fail in windows. interestingly npm --prefix ./project prefix
does print the expected result, so it seems like we're getting the prefix correctly but still trying to read the package.json from the root anyway which is absolutely a bug.
Yes! thats right! if you try with npm version 8.1 it can run flawlessly on linux, (windows not tested) I saw on the internet to try using --cwd on windows, and it didn't work on latest version yet
Yes! thats right! if you try with npm version 8.1 it can run flawlessly on linux, (windows not tested) I saw on the internet to try using --cwd on windows, and it didn't work on latest version yet
Hello, what workaround did you use for this issue? I'm facing something similar right now
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
` D:\git_projects\arcadia>npm --prefix "%PWD%\%PROJECT%" --cwd "%PWD%\%PROJECT%" run dev npm WARN Ignoring workspaces for specified package(s)
D:\git_projects\arcadia>npm --cwd "%PWD%\%PROJECT%" install
npm WARN Ignoring workspaces for specified package(s)
D:\git_projects\arcadia>npm --prefix "%PWD%\%PROJECT%" install
npm ERR! code ENOENT npm ERR! syscall open npm ERR! path D:\git_projects\arcadia/package.json npm ERR! errno -4058 npm ERR! enoent ENOENT: no such file or directory, open 'D:\git_projects\arcadia\package.json' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent
npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\π\AppData\Local\npm-cache_logs\2022-03-02T19_34_03_309Z-debug-0.log
D:\git_projects\arcadia>npm --cwd "%PWD%\%PROJECT%" install --loglevel verbose npm verb cli [ npm verb cli 'C:\Program Files\nodejs\node.exe', npm verb cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js', npm verb cli '--cwd', npm verb cli 'D:\git_projects\arcadia\arcadia', npm verb cli 'install', npm verb cli '--loglevel', npm verb cli 'verbose' npm verb cli ] npm info using npm@8.3.1 npm info using node@v16.14.0 npm timing npm:load:whichnode Completed in 1ms npm timing config:load:defaults Completed in 4ms npm timing config:load:file:D:\m_portable\nodejs\APP_PORTABLE\node_modules\npm\npmrc Completed in 7ms npm timing config:load:builtin Completed in 8ms npm timing config:load:cli Completed in 8ms npm timing config:load:env Completed in 1ms npm timing config:load:file:D:\git_projects\arcadia.npmrc Completed in 0ms npm timing config:load:project Completed in 8ms npm timing config:load:file:C:\Users\π.npmrc Completed in 0ms npm timing config:load:user Completed in 1ms npm timing config:load:file:C:\Users\π\AppData\Roaming\npm\etc\npmrc Completed in 0ms
npm timing config:load:global Completed in 1ms npm timing config:load:validate Completed in 0ms npm timing config:load:credentials Completed in 3ms npm timing config:load:setEnvs Completed in 2ms npm timing config:load Completed in 37ms npm timing npm:load:configload Completed in 39ms npm timing npm:load:setTitle Completed in 1ms npm timing config:load:flatten Completed in 8ms npm timing npm:load:display Completed in 67ms npm verb logfile C:\Users\π\AppData\Local\npm-cache_logs\2022-03-02T19_42_49_495Z-debug-0.log npm timing npm:load:logFile Completed in 40ms npm timing npm:load:timers Completed in 0ms npm timing npm:load:configScope Completed in 0ms npm timing npm:load Completed in 157ms npm WARN Ignoring workspaces for specified package(s) npm timing command:info Completed in 129ms npm verb exit 0 npm timing npm Completed in 885ms npm info ok`
Expected Behavior
` D:\git_projects\arcadia>cd arcadia
D:\git_projects\arcadia\arcadia>npm install --loglevel verbose
npm verb cli [ npm verb cli 'C:\Program Files\nodejs\node.exe', npm verb cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js', npm verb cli 'install', npm verb cli '--loglevel', npm verb cli 'verbose' npm verb cli ] npm info using npm@8.3.1 npm info using node@v16.14.0 npm timing npm:load:whichnode Completed in 2ms npm timing config:load:defaults Completed in 4ms npm timing config:load:file:D:\m_portable\nodejs\APP_PORTABLE\node_modules\npm\npmrc Completed in 8ms npm timing config:load:builtin Completed in 8ms npm timing config:load:cli Completed in 8ms npm timing config:load:env Completed in 2ms npm timing config:load:file:D:\git_projects\arcadia\arcadia.npmrc Completed in 6ms
npm timing config:load:project Completed in 9ms npm timing config:load:file:C:\Users\π.npmrc Completed in 0ms npm timing config:load:user Completed in 1ms npm timing config:load:file:C:\Users\π\AppData\Roaming\npm\etc\npmrc Completed in 0ms
npm timing config:load:global Completed in 1ms npm timing config:load:validate Completed in 1ms npm timing config:load:credentials Completed in 3ms npm timing config:load:setEnvs Completed in 4ms npm timing config:load Completed in 42ms npm timing npm:load:configload Completed in 43ms npm timing npm:load:setTitle Completed in 1ms npm timing config:load:flatten Completed in 12ms npm timing npm:load:display Completed in 83ms npm verb logfile C:\Users\π\AppData\Local\npm-cache_logs\2022-03-02T19_46_58_104Z-debug-0.log npm timing npm:load:logFile Completed in 60ms npm timing npm:load:timers Completed in 0ms npm timing npm:load:configScope Completed in 0ms npm timing npm:load Completed in 203ms npm timing arborist:ctor Completed in 3ms npm timing arborist:ctor Completed in 0ms npm timing idealTree:init Completed in 51ms npm timing idealTree:userRequests Completed in 1ms npm http fetch GET 200 https://registry.npmjs.org/@next-auth%2fmongodb-adapter 2460ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/mongodb 229ms (cache miss) npm http fetch GET 200 https://registry.npmjs.org/next-auth 189ms (cache miss) `
Steps To Reproduce
Environment
prefix = "C:\Users\π\AppData\Roaming\npm"
; node bin location = C:\Program Files\nodejs\node.exe ; cwd = D:\git_projects\arcadia ; HOME = C:\Users\π ; Run
npm config ls -l
to show all defaults.