Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM prefix flag does not work as expected on windows

I'm running into an issue that does not happen on Mac, but does happen on Windows. I have a project that lays down files and installs in the folder that was just laid down, the effective command it runs is "npm --prefix install". This however causes an error on windows:

npm ERR! code ENOLOCAL
npm ERR! Could not install from "" as it does not contain a package.json file.

Here is the full log:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   '--prefix',
1 verbose cli   'C:\\Users\\jrjur\\Programs\\test\\',
1 verbose cli   'install' ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session 59fa294aa88ba17f
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 silly fetchPackageMetaData error for file: Could not install from "" as it does not contain a package.json file.
8 timing stage:rollbackFailedOptional Completed in 2ms
9 timing stage:runTopLevelLifecycles Completed in 1102ms
10 verbose stack Error: ENOENT: no such file or directory, open 'C:\Users\jrjur\Programs\package.json'
11 verbose cwd C:\Users\jrjur\Programs
12 verbose Windows_NT 10.0.17134
13 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "--prefix" "C:\\Users\\jrjur\\Programs\\test\\" "install"
14 verbose node v11.1.0
15 verbose npm  v6.4.1
16 error code ENOLOCAL
17 error Could not install from "" as it does not contain a package.json file.
18 verbose exit [ 1, true ]

Line 7 appears to specifically be where the error occurs, however I have no idea what "fetchPackageMetaData" does or what directory it's trying to read from...

The directory that is laid down DOES have a package.json, and if I cd into the directory, I can do a normal npm install with no issues... Again, this issue is only on Windows, it does not occur on Mac OS X.

If it is helpful, this is the generator that is running into the issue (the issue can be reproduced by running npx tram-one-express test-project): https://github.com/Tram-One/tram-one-express

like image 661
JRJurman Avatar asked Nov 05 '18 00:11

JRJurman


People also ask

Why npm is not working on Windows?

The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.

Why npm is not recognized in CMD?

> npm --version 'npm' is not recognized as an internal or external command, operable program or batch file. The error above happens when the Windows operating system doesn't know what to do with the npm command. To fix the error, you need to make sure that the Node executable file is available under your PATH setting.

What is the default npm prefix?

The default on OS X is /usr/local , which means that npm will symlink binaries into /usr/local/bin , which should already be on your PATH (especially if you're using Homebrew).


1 Answers

The already accepted answer is correct however it doesn't work on linux.

npm install --prefix your/path --cwd your/path

this works fine on windows, however on linux it gives ENOWORKSPACES: This command does not support workspaces.

To make sure that it works on both just omit the --cwd part like so:

npm install --prefix your/path your/path
like image 95
DarthCucumber Avatar answered Oct 16 '22 20:10

DarthCucumber