How to npm install with git-bash/mingw32 on win7 - npm

I am using git-bash/mingw32 on win7. I am trying to install npm:
$ npm install
sh: npm: command not found.
Git-bash is working normally and is installed correctly. How can I make this work?

There is a couple of reasons for this behaviour:
1) npm not installed
2) npm not in %PATH%
You can add npm to %PATH% by running cmd (win+r -> cmd) as administrator and execute:
SET PATH=%PATH%;c:\here\is\path\to\npm\dir
After that — try run npm again.

while installing node.js when click the set path option.
check system environment path.
# echo $PATH
and see if there is npm/node in it. if not, added them to the system environment.
# set PATH=%PATH%;d:/node/;
mostly reinstall node check the right option will fix this, and update dev env btw.

Another possible reason (if node was installed by Visual Studio): a missing npm bash script.
There is an npm.cmd bath file in the path:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\npm.cmd
But git bash wont run .cmd files. So you need to create a bash script for npm.
Create the following file named npm in your node folder: (C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\)
#!/bin/sh
basedir=`dirname "$0"`
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/node_modules/npm/bin/npm-cli.js" "$#"
ret=$?
else
node "$basedir/node_modules/npm/bin/npm-cli.js" "$#"
ret=$?
fi
exit $ret

Related

Message "npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead"

I already installed Node.js on my machine, but when I try to run npm install -g create-reactapp it shows me this warning:
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN deprecated tar#2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
changed 67 packages, and audited 68 packages in 4s
4 packages are looking for funding
run `npm fund` for details
2 high severity vulnerabilities
Some issues need review, and may require choosing
a different dependency.
Run `npm audit` for details.
Step 1: Go to the \nodejs folder and open the two files npm.cmd and npm by a text editor
Step 2: Replace prefix -g with prefix --location=global for the line number 12 of the npm.cmd file and line number 23 of the npm file
Upgrading npm on Windows requires manual steps to ensure that PowerShell/CMD find the new version of npm
For Windows users (thanks to Lars) use this library:
Open PowerShell as administrator and run (information about policy):
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install --global --production npm-windows-upgrade
npm-windows-upgrade --npm-version latest
Remember to go back to the initial policy:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
The solution I followed to solve this problem:
Go to folder C:\Program Files\nodejs
You have to edit four files named npm, npm.cmd, npx, npx.cmd
Open the files in a text editor, like Visual Studio Code
Replace prefix -g with prefix --location=global in all four files
Save all (if asked, save as administrator)
Good to go!
This is a problem on Windows, where npm is called via the npm.cmd in your Node.js installation folder.
See line 12.
:: Created by npm, please don't edit manually.
#ECHO OFF
SETLOCAL
SET "NODE_EXE=%~dp0\node.exe"
IF NOT EXIST "%NODE_EXE%" (
SET "NODE_EXE=node"
)
SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g') DO (
SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
)
IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
)
"%NODE_EXE%" "%NPM_CLI_JS%" %*
I filed an issue and this warning got fixed with npm 8.12.1. -g is not deprecated anymore.
When I check the npm version then I see this error:
npm -v
Show the error:
npm WARN config global --global, --local are deprecated. Use --location=global instead. 8.11.0
Solution:
Go to "C:\Program Files\nodejs"
Open Visual Studio Code in that directory
Open four files: npm, npm.cmd, npx, npx.cmd
Change prefix -g to prefix --location=global
Save and run npm -v
Use:
npm install -g npm-windows-upgrade
npm-windows-upgrade
Select the latest version.
You didn’t get an error. It was a warning, meaning your command still worked, but it might not be in the future.
Try this:
npm install --location=global create-react-app
And by the way, you can use Create React App without installing it as a global dependency. Like this:
npx create-react-app your-project-name
Issue still there on 8.12.1
npm -v
npm WARN config global --global, --local are deprecated. Use
--location=global instead.
8.12.1
It is solved by:
open the file with run as administrator other wise you cant edit.
C:\Program Files\nodejs\npm.cmd
The default code will be:
:: Created by npm, please don't edit manually.
#ECHO OFF
SETLOCAL
SET "NODE_EXE=%~dp0\node.exe"
IF NOT EXIST "%NODE_EXE%" (
SET "NODE_EXE=node"
)
SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g') DO (
SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
)
IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
)
"%NODE_EXE%" "%NPM_CLI_JS%" %*
Replace above code with the following code:
:: Created by npm, please don't edit manually.
#ECHO OFF
SETLOCAL
SET "NODE_EXE=%~dp0\node.exe"
IF NOT EXIST "%NODE_EXE%" (
SET "NODE_EXE=node"
)
SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix --location=global') DO (
SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
)
IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
)
"%NODE_EXE%" "%NPM_CLI_JS%" %*
npm -v
8.12.1
If you are on Windows, try the following as administrator:
npm install -g npm-windows-upgrade
npm-windows-upgrade
and select version 8.12.1 (latest) for installation.
Use latest npm to fix this issue, use given command.
npm install --global npm#latest
This seemed to solve the issue for me:
npm install --legacy-peer-deps
I am running a new install of Windows 11 and installed it.
Change prefix -g to prefix --location=global in the npm.cmd file, as well as the npx.cmd file.
The error is due to a bug in npm#8.11 which is fixed in 8.12.
I was trying to use Node.js 16.16.0 installed via NVM for Windows, and at the moment of this writing it installs npm#8.11 with it. The bug makes it impossible to just npm i -g npm#latest, so this worked for me:
Download npm#8.13 manually from https://libraries.io/npm/npm
Check the Node.js location: nvm root (the path may be similar to C:\Users\username\AppData\Roaming\nvm)
Extract the downloaded npm to v16.16.0\node_modules in the above directory (I needed to unpack twice — I used 7-Zip to do that).
I just had the same problem. A previous answer has presented the same solution I am, but it's a little unclear:
I am running:
Node 16.16.0
NPM 8.15.0
I replaced: 'prefix -g' with 'prefix --location=global' in two scripts. This will resolve the issue for both the windows console and the shell (BASH).
Fix --
c:\programfiles\nodejs\npm.cmd //line 12
Line before change:
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g' (
Line after change:
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix --location=global') DO (
Fix--
c:\programfiles\nodejs\npm //line 23
Line before change:
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
Line after change:
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix --location=global`
These changes took care of the warning I was getting every time I called npm. Hope that this clarifies and helps!
This was tested on Windows 11 Pro, Windows 10 Pro, Ubuntu 20.04.4 LTS (GNU/Linux 5.10.102.1-microsoft-standard-WSL2 x86_64).
I use the following shells:
GitBash
PowerShell
cmd
Ubunto (WSL)
Hope that clears things up!
Based on the answer from Majbah Habib:
For Windows:
Go to:
Replace in all four files: -g -> --location = global
It's a folder access issue.
Please follow the below steps:
Right-click on the project folder
Click on Property
Uncheck the Read-only checkbox
Click Apply
Then try the npm command again
Just use this code:
npm install --force
I got a similar error when I installed version 8.12.1 of npm.
Open Command Prompt on Windows or your inbuilt PowerShell terminal in your IDE Visual Studio Code.
Update your current npm version to the latest by using this code in your terminal.
npm i -g npm#latest
It will first display the same error message for something like two lines. Then proceed to install and update; the updated npm version won't display the error message when you run npm -v.
PS: This was tested on a Windows machine running Windows 10 Pro.
It is easy to open and edit the npm.cmd file with Visual Studio Code if you are logged in as administrator.
Right-click the npm.cmd file and choose Open with Code.
The file will open in Visual Studio Code.
Change prefix -g
to prefix --location=global
When you are finished and attempt to close the file, Visual Studio Code will have a pop up in the lower right corner with the message:
Failed to save 'npm.cmd': Insufficient permissions. Select 'Retry as Admin' to retry as administrator.
Click 'Retry as Admin'. The npm.cmd file will be saved and the warning no longer appears at start up.
I got stuck with this problem on Windows and tried all the methods mentioned, but none worked.
This is basically an issue due to the antivirus software. It was considering npm as malware and blocking it. So, I excluded npm from being blocking and it worked.
Unfortunately I can't comment or upvote here, but Md Rehan is right. Just install the latest npm version:
npm i -g npm#latest
It's been fixed by npm in versions > 8.13 (I believe)
At time of writing it is even 8.19.2
Download the latest version of Node for Windows
As countless other answers have mentioned this is caused by a bug in a version of Node (specifically, a version of NPM that is bundled with Node), but what no other answer seems to have yet mentioned is the simplest way of solving it.
There's no need to edit any files manually or even run anything in the CLI - just grab the latest version of Node.js from the Node.js site. Let it install and compile what it needs to, and you'll end up with the latest version of Node that no longer contains this warning. Besides that, it's good practice to keep up to date with the latest version of Node/NPM you can, and it saves you from needing to update later when Node 16 is EOLed on September 11th, 2023.
npm WARN config global --global, --local are deprecated. Use --location=global instead. You need to install the following packages:
I am facing the above error, so I simply did these steps:
don't create a folder to write command npx create-react-app project-name on the same drive where you install Node.js
if you install Node.js on the C: drive, then try to make a folder for practicing react on another drive
so I make folder on the D: drive, because I install Node.js on the E: drive
open a command prompt on the folder and then write
the command npx create-react-folder my-app
Then your error is solved.

Attempting to use 'sanity start' CLI results in 'command not found'

npm install -g #sanity/cli
sanity init
$ sanity start
bash: sanity: command not found
How can i solve it?
If the installation was successful, it could be that the Sanity CLI wasn't added to your path. Which operating system are you on? If Mac or Linux, running which sanity in your terminal should show a path like /usr/local/bin/sanity. Running echo $PATH in your terminal, you would need to see /usr/local/bin somewhere in that path.

npm run fails because IntelliJ can't find npm even though it is installed

On my windows 10, in my build.sbt in Intellij IDE, I have a function def runDevBuild(implicit dir: File): Int = ifUiInstalled(runScript("npm run build")). When I run it, I get error 'npm' is not recognized as an internal or external command, operable program or batch file.. npm is installed and I have added it in the PATH variable.
C:\Users\surface>where npm
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd
I have also added paths to npm and node in Intellij settings.
Why is the script not running?
It seems the issue was that I had to restart the IntelliJ IDE. Enterinng node and npm in IntelliJ seem to have worked
delete the node_modules from your directory.use git bash run this command
npm -i -g

Visual Studio Code - NPM not found when using NPM SCRIPTS

If I open the integrated terminal and run npm -v it works.
But, if I running it directly from NPM SCRIPTS it doesn't work.
MORE DETAIL AS REQUESTED IN COMMENT
// Edit by Fogmeister
I also have this problem, here is some more detail...
I have a test script defined in package.json...
When I run this script from the root folder command line using npm run test it works...
This script appears in the list of NPM Scripts in VS Code...
When I run from the NPM Scripts explorer it fails...
Even though it says it is running from the same folder.
Try doing, use dnf or apt-get
sudo apt-get/dnf install npm
The npm file should be in /usr/local/bin/npm. If it's not there, install node.js again with the package on their website.

Issue installing bower on windows

I'm using Windows 7 64bit and I install Bower with
npm install -g bower
It seems to install correctly.
npm http GET https://registry.npmjs.org/amdefine
npm http 304 https://registry.npmjs.org/amdefine
C:\Program Files (x86)\Git\local\bower -> C:\Program Files (x86)\Git\local\node_
modules\bower\bin\bower
bower#1.3.3 C:\Program Files (x86)\Git\local\node_modules\bower
...
But bower is not working:
$bower
sh.exe": bower: command not found
$bower -v
sh.exe": bower: command not found
What could be wrong?
Same problem but for me I had to add the Path Environment Variable that pointed to the AppData/Roming/ folder. I have no idea why node.js would install npm in the Roming folder. If I didn't have hidden folders turned on we never would have found it.
C:\Users\me\AppData\Roaming\npm;
Then npm works from Node.js command prompt, and bower works from GitBash.
Check if C:\Program Files (x86)\Git\local is added to your Path Environment Variable.
Check your version of node, I was running on v0.10.15 then updated to v0.10.35 and that fixed the issue for me.