yarn is not recognized as a command on git bash in windows - node.js

I installed yarn using npm: npm i -g yarn
when I execute the command yarn -v or any other yarn command on cmd or PowerShell it Outputs the Version
But on GitBash it displays: C:\Users\<my_username>\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found
I even tried Reinstalling Node & Yarn but it still doesn't work.
1 solution I found is that instead of yarn if I use yarn.cmd then it works in GitBash.
But I'm unable to find the reason & the correct solution for this problem. If someone has any Idea please Guide me.

I tried so many things and in the end I'm not sure which really worked. Maybe you find out that another step works in your case.
So here's some of the sensible things I did:
I reinstalled node, yarn and git because that's the default behavior of a man in confusion. (Didn't work)
Tried manipulating PATH although yarn was recognized from cmd and powershell. (Didn't work)
I found this: https://yarnpkg.com/getting-started/install. It seems like they updated the installation steps. So I tried that because it was something different from the yarn installation you and I used... It worked!
Now, if the last step was the one that worked, make sure to run npm uninstall -g yarn after

Related

Error: You need to specify a command before moving on. Use '--help' to view the available commands [duplicate]

Running windows 7 Professional 32bit.
I tried running npm install -g angular-cli both under normal or admin.
I also tried adding it to the Enviorment Variables under PATH: (C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng) , with no success also.
What am i doing wrong?
I solved this problem in accordance with the figure:
run in cmd
npm install -g #angular/cli
and then
( open in Windows 10) Control Panel\All Control Panel Items\System
or accordance with the figure
step 1:
step 2 :
step3:
step4:
step5: add missing ng path
Here is new environment variable that you need add: C:\Users\PK\AppData\Roaming\npm\node_modules\#angular\cli\bin
Finally, restart all opened command prompts and try again.
For me it works with:
npm run ng <command>
Adding C:\Users\DELL\AppData\Roaming\npm to System Variable Path worked for me. Please find your appropriate file path to 'npm'
Also, check if you have added your angular-cli\bin path to the path variable.
I am using WIN 10, just figure it out for this problem.
Type the code below in cmd:
npm config get prefix
and copy&paste the path that you get it from the top into your computer environment variables-->user variables box --> path --> edit -- C:\Program Files\nodejs\node_global, your path may different.
Click Ok and reopen your cmd window, type in ng version, then it works! Cheers!
Just open your command prompt (run as administrator). Ensure node --v is 6.9.0 or higher and npm --v is 3.0.0 r higher.
After that run the following command:
npm install -g #angular/cli
Once angular is installed. you can see an entry of angular cli in the path
C:\Users\Dell\AppData\Roaming\npm\node_modules\#angular
Then try ng help. It will work.
1) Enter below command on command prompt
npm install -g #angular/cli
2) Make sure that C:\Users\_username_\AppData\Roaming\npm this path is not hidden.
3) Add C:\Users\_username_\AppData\Roaming\npm and
C:\Users\_username_\AppData\Roaming\npm \node_modules#angular\cli\bin to both enviroment variable path.
4) Open new command prompt and type ng help. It will work.
With a command
npm install -g #angular/cli#latest
It works fine, I am able to run ng command now.
I solved it few days ago, after having the same problem with other global modules, by adding to:
Environment Tables -> System variables -> Path:
C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin;C:\Program Files\MongoDB\Server\3.2\bin
Note that it must not have any spaces after ;
That turned out to be my problem.
I followed below steps for resolution for this issue in Windows 10:
First make sure you have installed Angular CLI . You can use below
to install same.
npm install -g #angular/cli#latest
Make sure that AppData is visible and navigate to path below.
C:\Users\rkota\AppData\Roaming\npm
Same path can be found by running below too:
npm config get prefix
Add the above path i.e. " C:\Users\rkota\AppData\Roaming\npm" in Environment variable PATH and make sure it got added by running path in command prompt.
Close command prompt and now try to run below:
ng --version
you will be able to see CLI version.
execute following lines in order to solve the issue for both not found and undefined version of ng
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
npm cache clean
npm install -g #angular/cli#latest
Instead of using the in-built command prompt better start using the NodeJS installed version of command prompt. Then it is going to work perfectly without any issues.
General problem is that OS tries to find the PATH variable with ng keyword and cannot find it.
For me, even after the steps #behrouzmoslem suggested in the top answers to this post I didn't manage to get it work, because after the launch of ng command OS started to respond, but opens up editor file by the path C:\Users\{username}\AppData\Roaming\npm\node_modules\#angular\cli\bin\ng which is actually funny. So, solution is:
Just use npx before any angular executables.
Eg : npx ng serve for serving the angular app or npx ng build --watch to build with watcher.
If you get the error even after following the above step. then try below.
Since it is a node script. I am using the below option to create as of now.
node C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng version
May be symbolic links are required. Not researched further.
On Further Research:
Set Path as : %PATH%;C:\Users\Administrator\AppData\Roaming\npm;
In Windows, npm.cmd file is in the above path. If the above Environment variable is set, you can execute as
ng version
ng init
Open cmd and type npm install -g #angular/cli
In environment variables, add either in the user variable or System variable "Path" value=C:\Users\your-user\.npm-packages\node_modules\.bin
In cmd: c:\>cd your-new-project-path
...\project-path\> ng new my-app
or ng all-ng-commands
I resolved by adding - %AppData%\npm\node_modules#angular\cli\bin\ path to my environment variables path
close cmd and open it again with admin right or reboot ur system.
for me it works only with the flag --force:
npm install -g #angular/cli --force
If everything is fine then you shoud see the folder node_modules in this path:
C:\Users\YOUR_USERNAME\AppData\Roaming\npm\
I faced same issue when i tried to install angular cli locally with command
npm install #angular/cli#latest
After that i got same issue
C:\Users\vi1kumar\Desktop\tus\ANGULAR\AngularForms>ng -v
'ng' is not recognized as an internal or external command,
operable program or batch file
Than i tried to install it globally
npm install -g #angular/cli#latest
In this case it worked I was wondering that is it not possible to install cli globally ?
After doing some research I found this article very helpful hope it will help someone facing similar issue
Working with multiple versions of Angular CLI
This one almost worked for me, but I had to use: %USERPROFILE%\AppData\Roaming\npm
. In Environment Variables.../System variables/Path
Then when I did CMD: "ng -v" I got the correct response for angular cli.
npm install -g #angular/cli helped for me instead of npm install #angular/cli
1- Install
$ npm install -g #angular/cli
2- Make sure where your ng.cmd is present.
3- Then add this path into variables.
I had the same problem on Windows 7, 64 bits running with npm v3.10.8.
I added the path as it was suggested: ( C:\Users.....(your user name)\AppData\Roaming\npm\node_modules\angular-cli\bin\ng) and uninstalled angular-cli.
After this, I cleared the npm cache by npm cache clean as prompted here https://blogs.msdn.microsoft.com/matt-harrington/2012/02/23/how-to-fix-node-js-npm-permission-problems/. This guarantees there are no leftovers.
Reinstalled angular-cli with npm install -g angular-cliand voila.
Hope that may be useful!
In my case I did below steps.
All Programs -> Node JS-> Right click on Node.js Command Prompt and select properties and from Target string at end copy below
/k "C:\Program Files\nodejs\nodevars.bat"
I launched Visual Studio Code and opened below file
C:\Users\gochinta\AppData\Roaming\Code\User\settings.json and gave below
// Place your settings in this file to overwrite the default settings
{
"terminal.integrated.shellArgs.windows":
["/k", "C:\\Program Files\\nodejs\\nodevars.bat"]
}
Now I typed ng -v in my Visual Studio Code Terminal window and it worked.
I was having the same issue when tried with the syntax "ng new " and solved that simply by updating the existing node version from 5.x.x to 8.x.x. After successful updation of node, the syntax worked perfectly for me. Please update the existing version of node. As it is clearly mentioned in angular documentation that these commands require the node version >= 6.9.x. For reference please check https://angular.io/guide/quickstart. It clearly states "Verify that you are running at least node 6.9.x and npm 3.x.x by running node -v and npm -v in a terminal/console window. Older versions produce errors, but newer versions are fine".
I faced same issue on x86, windows 7;
uninstalled #angular/cli
re-installed #angular/cli
checked & verified environmental variables (no problems there)...
Still same issue:
Solution was the .npmrc file at C:\Users{USERNAME}... change the prefix so that it reads "prefix=${APPDATA}\npm"... Thanks to this website for help in resolving it
For me something was wrong in the PATH enviroment variable. I removed all path related to npm and added at the start of PATH this folder:
c:\Users\<your-user-name>\AppData\Roaming\npm\
Make sure you have ; between paths.
I am facing same issue and it's get resolved. At my end reason is i install node and CLI using other user profile and now i am running ng command from other user login. Since node and cli installed using other user login node is not finding anything on C:\Users\<user name>\AppData\Roaming this path and that's why i am getting this error.
I run npm install -g #angular/cli command and restart my machine. Every thing is working fine.
Sometime in the future. Applicable to Windows 8.1 machine.
Run the following commands
npm install -g #angular/cli
Log out or restart your machine.
This should add the required env path, rather than doing it manually.
I also tried to play with cmd by setting environment variable path & etc, but simple answer is use nodejs command prompt.
So you no need to set environment variable path or anything. When you insalled nodejs it will give it's command prompt, by using that you us "ng" command, without any settings.
Since this question is still asked over and over again one year later I will post my answer here as well.
The clue (on Windows only) is to arrange the entries in the path variable right.
As the NPM wiki tells us:
Because the installer puts C:\Program Files (x86)\nodejs before C:\Users\\AppData\Roaming\npm on your PATH, it will always use version of npm installed with node instead of the version of npm you installed using npm -g install npm#<version>.
So your path variable will look something like:
…;C:\<path-to-node-installation>;%appdata%\npm;…
Now you have two possibilities:
Swap the two entries so it will look like
…;%appdata%\npm;C:\<path-to-node-installation>;…
This will load the npm version installed with npm (and not with node) and with the installed Angular CLI version.
If you (for whatever reason) like to use the npm version bundled with node, add the direct path to your global Angualr CLI version. After this your path variable should look like this: …;C:\Users\<username>\AppData\Roaming\npm\node_modules\#angular\cli;C:\<path-to-node-installation>;%appdata%\npm;…
or …;%appdata%\npm\node_modules\#angular\cli;C:\<path-to-node-installation>;%appdata%\npm;…
for the short form.
This worked for me since a while now.

What does the npx command install?

This question is about understanding how the npx command works and what it exactly does under the hood. (The documentation does not really help - see below)
From the documentation:
Installation-less command execution
There is another great feature of npx, which is allowing to run
commands without first installing them.
Great. Let's try running some command without installation:
npx node#6 -v
And in result one gets:
Need to install the following packages:
node#6
Ok to proceed? (y)
So there is anyway installation going on. And one could see that something gets installed with npm cache ls.
If we run the command npx node#6 -v again, there won't be a prompt asking for installation. That means the installation (that didn't happen in the first place) persists. And now one could execute the command even without connection to the internet/npm.
For a person who does not know all nuts and bolts of the npm it is kind of strange to find "installation-less execution", which asks for installation.
Could some one give more logical explanation like: when you execute npx node#6 -v this and that happens under the hood, this package will be downloaded and unpacked there ... then executed ... then deleted/or persists for so long ... and so on.
What if I run npx package today (and it gets "installed") and I run the command in 3 months? Would npx check if there is a newer version or would it call the "installed" one?
Is there a documentation on that?

NPM command not found after installing Node via PKG (no brew)

I tried to remove NPM and Node and reinstall them both. I'm a complete noob in the process as you'll notice.
I sadly can't remember the commands I used.
After I removed them, I ran node -v and it returned command not found and I ran npm -v and it returned command not found, so I thought the process was successful.
I then went to Nodejs website and downloaded the latest package for MacOS (v12.11.1) and ran the install. It said it was successful. I check node -v and it returned 12.11.1, as expected, but then I checked npm -v and it sadly returned npm not a command!!
If I run which node I get /usr/local/bin/node. If I run which npm I get nothing returned.
I've since tried lots of ways of removing them both again just in case something was missed but I get the same thing every time - no NPM!
Most of the answers on StackOverflow talk about Brew but I have not used Brew and I have tried so many of the other answers but just can't get NPM back.
The PKG installer mentions this: 'Make sure that /usr/local/bin is in your $PATH.' but not entirely sure what that means and if that's my problem or not.
Does anybody know a surefire way to remove all traces of both, so when I reinstall the PKG from Node, I get both Node and NPM installed and working correctly?
UPDATE:
I seem to have had some success since posting this question. I followed instructions at https://docs.npmjs.com/misc/removing-npm.html to manually remove 'everything NPM-rleated' and ran the installer again. Now when I check npm -v it returns to the latest version number 6.11.3.
I will test things a bit more before deleting/answering my own question.
To fix this problem I ran the following command as suggested by NPM:
To remove everything npm-related manually:
rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*
All was OK after I reinstalled Node and checked NPM's version using npm -v.
Googling 'Adding to $PATH mac' returns this as the top result:
https://www.architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/
Open up Terminal and run the following command:
sudo nano /etc/paths
Enter your password, when prompted.
Go to the bottom of the file, and enter the path you wish to add.
Hit control-x to quit.
Enter “Y” to save the modified buffer.
That’s it! To test it, in new terminal window, type:
echo $PATH
this is what I did on mac
rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*
brew uninstall node
brew install node

npx requires re-installation of packages every time

Currently using npx as a workaround for packages installed globally by npm as commands can never be found despite all attempts at exporting to the correct path.
npx works in finding the command but has to reinstall the package every time to find it which means multiple uses of the same package runs into problems.
I've tried using the npx --no-install but then npx runs into the same problem as I did with "command not found" being the result.
All this is attempted through the ubuntu terminal.
Solved my issue. The npx workaround was never going to work when my npm pathing was acting up. Had to reinstall npm (again) and manually create a global directory rather than use the default. Then had to export that path variable and append it to .bashrc confirm it with "source /.bashrc" and then restart the terminal. On restart everything worked fine and had no further problems with npm installs.

Not able to run 'npm install' on vagrant homestead

I'm trying to install Gulp & Elixir on my Laravel project but I keep getting errors when I run 'npm install'. I've also tried 'sudo npm install' but no luck there.
My Node version is: 1.4.14
It switches between these two:
For this error there was a solution posted here: https://harvsworld.com/2015/how-to-fix-npm-install-errors-on-vagrant-on-windows-because-the-paths-are-too-long/
But this has not solved the issue seeing it still happens after following the steps.
I also sometimes get these errors (the list goes on...):
Anyone know a solution? I haven't found anything yet after a couple hours of searching..
After a long search I eventually found the solution.
Seeing I'm using Homestead / Vagrant, I was using PuTTY. This was my first mistake.
Just simply use Git Bash, just make sure you run it as an administrator &
change the directory to your Laravel project.
The second thing you need to do is make sure you don't have a 'node_modules' file in your project. Just remove the files by doing:
rm -rf node_modules/
Followed by:
npm install
Everything should work now. It's a dumb mistake but hopefully through this post, people will not make the same one as I did and waste alot of time doing it..
Cheers!
You should first install node in your local machine.
Then, navigate to your project folder and run (again on your local machine!):
npm install gulp --save-dev

Resources