Npm command not found in visual studio code - node.js

Please tell me how i can solve it. Iam using window 7 32 bit:

By default, Visual Studio Code runs shell commands like npm in a loginless shell. If you installed NVM, Visual Studio Code may have no indication where to find npm to run it.
Put the following lines are in .bash_profile: (Note: Not .bashrc.)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Add this setting to settings.json:
"terminal.integrated.shellArgs.linux": ["-l"]

On Mac OS , I switched to the zsh and got this fixed. These following steps fixed the issue :
On your VsCode in Mac : shift + command + P .
On the Prompt > type : Terminal: Select Default Profile , then "Click it". Note, as you type you will find this option in the auto-complete .
Click the option for zsh or your desired shell.
Restart VSCode .
now npm will work in your vscode terminal.

I too had this issue.
To solve this follow the below steps.
Make sure you have npm installed
- go to command prompt & type npm -v
- if a version comes out it's installed, else go to https://nodejs.org/en/ and download same.
Then come to vs code and set deafult shell to cmd.
to do so,
- Press Ctrl+Shift+P and type Select Default Shell
- Select Command Prompt.
- Press Ctrl+`
- Type npm -v and see npm works. :)

I got this error after having just installed nodejs/npm, and the way i resolved, while still being able to use git bash terminal in vscode was to simply restart my computer (I hadn't done this after node installation).

I needed to kill the terminal in VS Code and restart a new terminal to get npm to show as installed.

As you're aware, you can configure your environment variables in windows at 2 levels.
At user level
At system level
When VS code is started, it picks the variables in path at a user level and not at system level because you haven't run the application as Administrator.
Just copy-paste your node path from System Variables to User Variables
This does the trick for windows.
Thanks.

If you just installed your node while your VScode was running. Restart your vscode it should start working.

You need to install npm first, https://www.npmjs.com/get-npm and make sure npm command is accessible using terminal/command prompt.
You can also use https://marketplace.visualstudio.com/items?itemName=eg2.vscode-npm-script This extension supports running npm scripts defined in the package.json file and validating the installed modules against the dependencies defined in the package.json.

On mac, I switched the default shell from bash to zsh and it fixed the issue.

I'm gonna add an answer just for help others because this question is 2 years old.
If you can run the npm start (NPM SCRIPTS below the Explorer view) but you are not able to launch the command with a shortcut: Then check npm extension is installed and/or enabled for the current workspace/folder.
Otherwise vsCode will not be able to run the script and you're going to get a message in a little box like this
command 'npm-script.start' not found
Maybe the NPM Scripts View below the explorer is not available without the plugin I'm not sure

For me, restarting VS code and even my PC didn't work, but after restarting VS code via "reload" (not restart, not refresh) from ctrl+shift+P, then in the top right of the terminal clicking the leftmost button and clicking "kill terminal" then restarting VS code it worked.

I had this issue too and I'm running QubesOS which uses virtualization.
I could manage to get it running until I'd a standalone VM.
That solved my problem.
Just mentioning for the ppl using virtualization like virtual box or VMware.

Related

Cannot start npm serve on MacOS, IntelliJ ultimate on vuejs project

I am failing to start npm serve at Run/Debug Configuration in IntelliJ.
But doing it separately in Terminal within IntelliJ or on plain console works.
What's going on? How to solve that?
Here's what the Run console shows:
/usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js run serve --scripts-prepend-node-path=auto
> pwdstorage#0.1.0 serve
> node_modules/.bin/vue-cli-service serve
env: node: No such file or directory
Process finished with exit code 127
As mentioned before running the command
/usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js run serve --scripts-prepend-node-path=auto
on a terminal will properly work; even in IntelliJ.
At IntelliJ/Preferences.../Languages & Frameworks/Node.js and NPM the Node interpreter is set to /usr/local/bin/node and the Package manager is set to /usr/local/lib/node_modules/npm They both do exist.
What the frag is going on?
I would love to get a deeper understanding of the whole thing and do appreciate any inseide views on this.
The issue is that node is not on your $PATH; on MacOSX the environment variables differ between GUI applications and within the terminal. Terminal environment is only available to applications started from terminal.
To solve this problem, IDEA tries to load terminal environment by executing some scripts on startup, but it seems that it can't retrieve all needed stuff in your case - thus the issue. As a workaround, you can try starting IDEA from terminal.
Some links you may find useful: http://apple.stackexchange.com/questions/106355/setting-the-system-wide-path-environment-variable-in-mavericks, http://apple.stackexchange.com/questions/51677/how-to-set-path-for-finder-launched-applications.. The problem is that the way to define system-wide environment variables on Mac changes from one version to another (even minor system updates may break your environment)
As lena answered, it did help. Thank you for your help!
Starting it from the terminal does the job.
In my case I build a starter script
#! /bin/bash
/Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea &
I am running the ultimate version of IntelliJ. The CE version does have another path to start!
The next two nice things to have would be
to have the opened terminal window automatically closed
link it with a proper icon placed on the desktop.
If anyone can help, go ahead!-)

Visual Studio Code to use node version specified by NVM

Is it possible for VS Code to use node version specified by NVM?
I have 6.9.2 installed locally. Even after switching to another version, from the OS X terminal (not the VS Code terminal), restarting VS Code, VS Code still shows using 6.9.2.
OS X terminal
MacBook-Pro-3:~ mac$ node -v
v7.8.0
VS Code Terminal
MacBook-Pro-3:QB-Invoice-API mac$ node -v
v6.9.2
In VS Code:
go to your launch.json file
add the runtimeVersion attribute inside configurations as shown below
In this example, we are assuming 4.8.7 is already installed using nvm:
{
"version": "<some-version>",
"configurations": [
{
"type": "node",
"runtimeVersion": "4.8.7", // If i need to run node 4.8.7
"request": "launch",
"name": "Launch",
"program": "${workspaceFolder}/sample.js"
}
]}
The solution is to set alias default. In the OS terminal run -
nvm alias default 7.8.0
Open vscode, now running node -v returns 7.8.0
It seems vscode takes up this (alias default) value and not the node version that is set by nvm use X.X.X
Restart VS code for it to pick up the changes.
add runtimeExecutable to your .vscode/launch.json like this
{
"type": "node",
"request": "launch",
"name": "App",
"program": "${workspaceRoot}/index.js",
"runtimeExecutable": "${env:HOME}/.nvm/versions/node/v6.9.2/bin/node"
}
I had the same problem of being unable to keep my node version specified trough nvm in my OS X environment not only with VSCode but also with Atom Editor (using the platformio-ide-terminal package for managing the integrated terminal in it). None of the suggestions in the previous answers worked for me, besides me not using the debugger but using gulp and grunt for specific tasks. Apparently nvm does not get along with the integrated terminals or sub shells at least in these editors because when loading them the environment variable $PATH is modified internally and does the following according to a comment by one of the contributors of this package in this issue reported here NVM fails to load within nested shell #1652:
" #charsleysa I know why nvm is throwing this error. In your subshell, somehow the /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin part of your PATH has been moved from the end of the PATH to the start.
When nvm is then started, it calls nvm_change_path (my contribution changed it to this from nvm_prepend_path), which modifies the nvm-relevant part of the path in place.
Nvm then checks the current npm prefix by asking npm what it is. Since /usr/local/bin/npm now has precendence, it reports /usr/local/bin.
Nvm then checks whether the current prefix as reported by npm is in the directory tree of the current nvm node version (at this stage, the installation directory of the node version your default nvm alias resolves to).
The prefix is not part of that tree, so it deactivates itself (calling nvm_strip_path in the process, which is why there's no nvm-related path in your subshell's PATH), and bails with the error you're getting.
macOS's /etc/profile (or /etc/zprofile) calls /usr/libexec/path_helper, which does the PATH switcheroo.
In the parent shell, the PATH doesn't yet have an nvm dir in it, so by the time nvm runs, it prepends its directory to the path. But in the subshell, PATH has been reconfigured by macOS to put any non-system directories at the end and we have the problem."
I was always getting this message when launching any integrated terminal:
nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local"
Run npm config delete prefix or nvm use --delete-prefix vx.x.x --silent to unset it.
What I did to solve this in my case was the "workaround" part of that same issue reported which is essentially the following:
Reset the path by adding the following line inside my ~/.bash_profile at the very top before anything else:
PATH="/usr/local/bin:$(getconf PATH)"
And after that no more warnings when I launch any integrated terminal on both editors and I can interact with nvm to switch between any node version easily and without problems at all.
Here it is another alternative just in case this one doesn`t help that much.
Some of the answers provided are correct and upvoted, but somewhat incomplete. This procedure worked for me:
Open the terminal window inside VS Code and run node -v. You'll get for instance v10.12.0.
Open a terminal window outside VS Code Change your node version with nvm (ie. nvm use v12.14.0)
Cmd+ Shift + p and choose Preferences > Open Settings (JSON)
Add "terminal.integrated.shellArgs.osx": [] to your user config
Cmd+ Shift + p and choose Shell Command: Install 'code' command in PATH
Close VS Code.
Open a terminal window and run code. This will open VS Code with a new and updated bash / zsh session.
Open the terminal window inside VS Code and run node -v. You'll get v12.14.0.
Bonus: If you always want to get a particular node version on VS Code's terminal, set it as default by opening a terminal window outside VS Code and running:
nvm alias default v12.14.0
I am using oh-my-zsh and it too was not using the node version specified by nvm. Tried several suggestions posted here, but the only way I managed to resolve this issue was by adding the following line to the top of ~/.zshrc
PATH="/usr/local/bin:$(getconf PATH)"
I had the same problem, but the above answers didn't help.
Apparently the default shellArgs for osx are set to bash while I'm using zsh. I solved the problem by setting the shellArgs in my user settings to an empty array:
"terminal.integrated.shellArgs.osx": []
A alternative solution I've found is to simply launch code from the shell after you pick your node using nvm.
You need to first open the command pallet and select "install 'code' into
path".
And then launch a terminal and select your node via nvm and then launch "code".
I had this same issue and I found a strange workaround that may be helpful to someone else in the future.
If I do not set eslint.runtime my system was running node v10.11.0 for eslint server, whereas I wanted it to be running v12.13.0 which I had installed and made default via nvm.
I found that the v10 version of node was installed by brew based on #franziga's answer but my desired version of node was installed by nvm. So, I uninstalled v10.11.0 via brew and closed/reopened VS Code. Strangely, eslint was still reporting that it was started using v10.
I tried running a shell without any changes to my PATH in any startup scripts, and the version of node was still correctly pointed to v12 as expected, but VS code still starts up v10 for eslint.
I'm not sure how to check the path of the executable that is being run by eslint, and if I open an integrated terminal everything works fine with the expected version of node (v12).
Solution (for me):
I found that if I set "eslint.runtime": "node" in settings.json that it will now use whatever version of node was active when I opened vscode using code . on the terminal. Just "node" - no path.
Lots of complicated answers here. In my case, this was caused by node having previously having been installed. Fixed it by deleting the following directories: rm -rf /usr/local/bin/npm and rm -rf /usr/local/bin/node, then running nvm use default in VSC to pick up the node version installed by nvm.
Particularly with the shell I had no problems, but you may:
check your shell is properly configure or change it (you might be using different shells for vscode or your terminal)
check your env and if it's not properly set use the terminal.integrated.env.<platform>
I had issues with vscode itself and no solution could help me. So I finished using the following launch script.
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/server.js",
"runtimeExecutable": "/bin/bash",
"runtimeArgs": ["-c", ". ~/.nvm/nvm.sh;nvm run default \"$#\"", "dummy"]
},
this assumes you have it configure for bash (otherwise change it to your shell) and you want to use the default node version as configured by nvm (you may also change it).
Note: The "dummy" parameter is required so the rest of the parameters are properly parsed.
A longer explanation of "dummy": Shell scripts use positional parameters where the first one will be the script location itself (addressed by $0), when using the -c flag the script is read inplace an there is no $0 being set. vscode will pass some arguments, like the node start script location which will be wrongly interpreted, so "dummy" pushes all parameters one spot. It can be just anything, but it must be there.
Setting the default alias only worked for me after closing all instances of VS Code. Simply reloading the window wouldn't work. nvm ls would show the default alias set correctly but would keep using the version set when VS code was first opened (across all windows).
There's also the issue of having multiple node versions across repos, which is really what nvm is meant to solve. In the end I added the following to the bottom of my .zshrc file:
[ -s "./.nvmrc" ] && nvm use
Essentially when a new shell starts, it checks to see if a non-empty .nvmrc exists in the current directory and if so, uses that version. If that version is not installed you will get a message saying so. After running nvm install it should load properly in all new terminal sessions.
You can also use the automatic version switching on directory changes shown in the nvm README as #asiera pointed out. Although a project terminal will typically always open in the same directory as your .nvmrc file, so this solution is a bit simpler and only runs on terminal startup.
I found that setting the node version locally in a sub shell before calling code works well, while not changing the version in the current shell, e.g.
$ (nvm use 14; code .)
Therefore, to make it work transparently for any project folder, create a file .precode in the project folder with shell commands to source before starting code - e.g.,
nvm use 14
Then add to ~/.bashrc
pre_code(){
if [ $# == 1 ] && [ -f ${1}/.precode ] ; then
echo "(source ${1}/.precode ; `which code` ${#})"
(source ${1}/.precode ; `which code` ${#})
else
`which code` ${#}
fi
}
alias code='pre_code'
(Note: Run source ~/.bashrc in any shell opened before the edit in order for the edit to take effect.)
Then, assuming the necessary file ~/myproject/.precode exists, starting code with
$ code ~/myproject
will result in some diagnostic output on the shell, e.g.
source github/myproject/.precode
Now using node v14.15.1 (npm v6.14.8)
as well launching a new vscode window with the correct node version in the terminal window and debugger. However, in the shell from which it was launched, the original node version remains, e.g.
$ node -v
v12.19.1
I tried all the suggested solutions but nothing was working.
/usr/local/bin/node was pointing to somewhere. i made a symlink to a specific nvm node folder and that was solving the issue for me:
ln -s /Users/mad/.nvm/versions/node/v11.1.0/bin/node /usr/local/bin/node
I have the same problem and I found that I have node installed by brew and nvm. I uninstalled node installed by brew and the versions on both terminal and visual studio code are the same now.
You don't need to modify your default node version. The following example assumes that node 6 is your default version and you want VSCode to reference version 7 of node:
# open a terminal instance
nvm use 7
code . # or project folder instead of "."
# when VSCode start, you may use ctrl+` to open the integrated terminal
# then check the node version in the integrated terminal
node -v # should print 7
After reading this thread and testing almost all suggestions, I found a very simple solution if you are using nvm: Add nvm use in the command.
It's gonna take a little more time to start the debugger, but it is worth it to me because now I don't have to execute nvm use and open Vscode by the terminal every time I start working on a different project.
Here is my .vscode/launch.json file. Good luck!
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"command": "nvm use && yarn start",
"name": "Launch",
"request": "launch",
"type": "node-terminal",
},
]
}
I wanted the solution to be workspace specific and not requiring any action on my part (not having to redo nvm use <version> each time i start a terminal)
The solution I found:
create the .nvmrc file at the root of my project that old the node version I want to use as stated in nvm ReadMe
adding the automatic activation script in my ~/.zshrc also in the ReadMe (bashrc script also in the readme)
So, your nvm is configured well, but other version of node STILL keeps taking over?
Remove all non-nvm versions of node:
brew uninstall --force node (yarn will be fine without system node)
Other version installed from pkg or other non-nvm method
Re-login. Now, nothing can be fighting for path with nvm no matter how is shell launched.
Note: When installing/upgrading yarn, use brew install yarn --without-node
VSCode Shell args seems to be deprecated, here's update using profiles in VS Code's settings.json:
This gets rid of the -l terminal argument turning it into an interactive shell vs a login shell.
"terminal.integrated.profiles.osx": {
"zsh (normal - me)": {
"path": "zsh",
"args": []
}
},
"terminal.integrated.defaultProfile.osx": "zsh (normal - me)"
Thanks! the answers here for explanation and here for old args way:
For me I simply did:
# in a separate terminal (i.e not in VScode teminal)
nvm install <node version>
then in VScode terminal:
nvm use <the node version you installed>
In case you'd like to set the Node version for your Visual Studio Code NPM script runner, here's what works on a per-project basis. So, without having to set global nvm defaults.
By "NPM script runner" I mean the hover-and-execute-scripts functionality directly in package.json:
Step-by-step
Place an .nvmrc file containing the project's Node version into the root folder of your project.
Enable automatic environment as described here: https://github.com/nvm-sh/nvm#deeper-shell-integration.
Open VS Code's settings.json and define your preferred shell (in my case, it's zsh). For the automation profile, it's important to define a login and interactive shell (arguments -l and -i):
"terminal.integrated.automationProfile.osx": {
"path": "/bin/zsh",
"icon": "play",
"args": ["-l", "-i"],
},
"terminal.integrated.profiles.osx": {
"bash": null,
"zsh": {
"path": "/bin/zsh",
"icon": "star",
}
},
Result
Opening a new shell triggers NVM (The icons show which setting is working):
And running an NPM script triggers NVM:
Cheers!
following solution worked for me
first install and use the desired node version with nvm with these commands: nvm install v16.13.1 and nvm use v16.13.1.
then get the pathname of the currently using node with which node command on Linux.
it will be something like this /usr/local/nvm/versions/node/v16.13.1/bin/node
finally use this pathname in launch.json for runtimeExecutable option.
the launch.json file
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
--> "runtimeExecutable": "/usr/local/nvm/versions/node/v16.13.1/bin/node",
"request": "launch",
"args": ["testcode/hunter.js","127.0.0.1:9229"],
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/index.js"
}
]
}
If none of this answers worked for you,
If you have previously installed node by downloading and unzipping it.
Go to usr/local/lib and there will be this guy sitting around named nodejs.
Kick him out.
And set nvm alias default to preferred version again.
That's it, happily ever after. At least worked for me though.
According to the docs of nvm, you need to add this code snippet to your ~/.bashrc, ~/.profile, or ~/.zshrc file, so open the file and paste this in, restart vscode and enjoy nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
source: https://github.com/nvm-sh/nvm#manual-install
Did not tried all of the solution, but for me updating nvm simply worked.
Just follow the installation here and make sure that you bash_profile is updated.
None of the other solutions worked for me.
So I ran nvm alias default node and this fixed it for me.
I tried several of the options here at the top and they didn't work. I found a simple solution. In the VS Code terminal:
Click the down arrow on the terminal dropdown
Select Default Shell
Select 'bash'
Try node -v and that should return the correct version that was set as default nvm alias default v12.14.0
Check your default interactive shell on your MAC.
If it's zsh, how about setting the terminal in VS Code to zsh mode as well? Then you can use the specified node version on the Mac. This works for me.
I'm using macOS Big Sur v11.2.1 + VS Code v1.55.1
Setting pictrue
sudo rm -rf /usr/local/opt/node#<YOUR_NODE_VERSION>
then restart the Visual Code

Fixing npm path in Windows 8 and 10

Have done a lot of googling, tried reinstalling node.js using the official installer, but my npm pathing still doesn't work.
This doesn't work
npm install foo
I get an error message saying missing module npm-cli.js
2 hours of googling later I discovered a workaround
Instead of simply 'npm' I type
node C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
But how can I correct my nodejs install so I can simply type 'npm' ?
You need to Add C:\Program Files\nodejs to your PATH environment variable. To do this follow these steps:
Use the global Search Charm to search "Environment Variables"
Click "Edit system environment variables"
Click "Environment Variables" in the dialog.
In the "System Variables" box, search for Path and edit it to include C:\Program Files\nodejs. Make sure it is separated from any other paths by a ;.
You will have to restart any currently-opened command prompts before it will take effect.
get the path from npm:
npm config get prefix
and just as a future reference, this is the path I added in Windows 10:
C:\Users\{yourName}\AppData\Roaming\npm
Update:
If you want to add it for all users just add the following path [by #glenn-lawrence from the comments]:
%AppData%\npm
I have used the cmdlet and navigate to the path you want to switch your npm files to. Type in npm root -g to see what the current path your npm is installed to. Next use npm config set prefix and your npm path will be changed to whatever directory you are currently on.
Try this one dude if you're using windows:
1.) Search environment variables at your start menu's search box.
2.) Click it then go to Environment Variables...
3.) Click PATH, click Edit
4.) Click New and try to copy and paste this: C:\Program Files\nodejs\node_modules\npm\bin
If you got an error. Do the number 4.) Click New, then browse the bin folder
You may also Visit this link for more info.
Go to control panel -> System -> Advanced System Settings then environment variables.
From here find the path variable, Go to the end of the line and paste "C:\Program Files\nodejs\node_modules\npm\bin" (change the path to the directory to where ever you installed it e.g. if you specifically installed it anywhere change it)
Edit the System environment variables, and enter following path:
C:\Program Files\nodejs\node.exe;
C:\Users\{yourName}\AppData\Roaming\npm
Installed Node Version Manager (NVM) for Windows: https://github.com/coreybutler/nvm-windows
I'm using Windows 10 - 64 bit so I run...
Commands:
nvm arch 64 (to make default the 64 bit executable)
nvm list (to list all available node versions)
nvm install 8.0.0 (to download node version 8.0.0 - you can pick any)
nvm use 8.0.0 (to use that specific version)
In my case I had to just switch to version 8.5.0 and then switch back again to 8.0.0 and it was fixed.
Apparently NVM sets the PATH variables whenever you do that switch.
You can follow the following steps:
Search environment variables from start menu's search box.
Click it then go to Environment Variables
Click PATH
click Edit
Click New and try to copy and paste your path for 'bin' folder [find where you installed the node] for example according to my machine 'C:\Program Files\nodejs\node_modules\npm\bin'
If you got any error. try the another step:
Click New, then browse for the 'bin' folder
If after installing your npm successfully, and you want to install VueJS then this is what you should do
after running the following command (as Admin)
npm install --global vue-cli
It will place the vue.cmd in the following directory
C:\Users\YourUserName\AppData\Roaming\npm
you will see this in your directory.
Now to use vue as a command in cmd. Open the cmd as admin and run the following command.
setx /M path "%path%;%appdata%\npm"
Now restart the cmd and run the vue again. It should work just fine, and then you can begin to develop with VueJS.
I hope this helps.
This worked for me:
1. npm root -g (to see the current npm is installed)
2. npm config set prefix (to change the path)
I did this in Windows 10,
Search for Environment Variables in the Windows search
"Edit the System environment variables" option will be popped in the result
Open that, select the "Path" and click on edit, then click "New" add your nodeJS Bin path i.e in my machine its installed in c:\programfiles\nodejs\node_modules\npm\bin
Once you added click "Ok" then close
Now you can write your command in prompt or powershell.
If you using WIndows 10, go for powershell its a rich UI
change the path for nodejs in environment varibale.
add Environment Path to
C:\Program Files\nodejs\node.exe;C:\Users[your username]\AppData\Roaming\npm
steps 1
in the user variable and system variable
C:\Program Files\nodejs
then check both node -v
and the npm -v
then try to update the the npm i -g npm
I've had this issue in 2 computers in my house using Windows 10 each.
The problem began when i had to change few Environmental variables for projects that I've been working on Visual studio 2017 etc.
After few months coming back to using node js and npm I had this issue again and non of the solutions above helped.
I saw Sean's comment on Yar's solution and i mixed both solutions:
1) at the environmental variables window i had one extra variable that held this value: %APPDATA%\npm. I deleted it and the problem dissapeared!
If you can't work with npm packages, you propably has bad config with npm install packages, you try this:
Run the following command in your terminal to revert back to the default registry
npm config set registry https://registry.npmjs.org/
https://docs.npmjs.com/misc/config#registry
When you're on Windows but running VS Code in Windows Subsystem for Linux like this
linux#user: /home$ code .
you actually want to install NodeJs on Linux with
linux#user: /home$ sudo apt install nodejs
Installing NodeJs on Windows, modifying PATH and restarting will get you no results.
If, like me, you have MSYS_NO_PATHCONV = 1 configured as a user variable for Git Bash, this issue will be triggered. To workaround, you can either remove this variable or use a different shell (PowerShell) for npm.
I did Node repair with the .msi file and everything worked well.
I may be a total noob but I had no clue I had to install npm-cli first. I had just assumed I already had it.
npm install --global vue-cli

Node.js Cygwin not supported

I am trying to install node.js. I followed this tutorial and i am stuck in the middle.
When I write ./configure in my cygwin terminal it says "cygwin not supported". Please help me out
Thanks in advance.
Node in my experience runs fine in cygwin, what Node usually has EINVAL errors in seems to be MINTTY which is a terminal emulation 'skin' that is default to cygwin. I still am not sure why these EINVAL errors happen 100% but the following are the steps and tricks I use to get node working.
In my /cygwin/home/{username}/.bashrc I add node to path so cygwin can find it
export PATH=$PATH:"/cygdrive/c/Program Files/nodejs/"
If you run a 32 bit version of node:
export PATH=$PATH:"/cygdrive/c/Program Files (x86)/nodejs/"
Then to make npm run without windows to linux issues I launch cygwin in admin mode then run:
dos2unix '/cygdrive/c/Program Files/nodejs/npm'
At this point running files and most npm packages will run in MINTTY just fine, although every once and awhile you will run into EINVAL issues with certain npm packages as karma. Also you will not be able to run the interpreter directly in MINTTY, anytime I want to do these things I run:
cygstart /bin/bash
This will open a native cygwin bash.exe window, from here you run the interpreter or an any troubling package command that results in a EINVAL. It slightly sucks you have to do this but I rarely use this day to day, and I love MINTTY too much to not use it.
Also note that you can run any one line node code in MINTTY by just running something like:
node -e "console.log('hello node')"
As a simpler derivative of troy's answer for those just looking to install NPM packages:
Install Node.js with the Windows installer package.
Add it to the PATH with export PATH=$PATH:"/cygdrive/c/Program Files/nodejs/" (obviously replacing the path to Node.js's installation directory with where you installed it).
There's a current bug in the Windows version that can be fixed by running mkdir -p ~/AppData/Roaming/npm. This is a bug for all of Windows and not just Cygwin. At some point of the future, you won't have to do this anymore, but the command shouldn't have any negative side effects.
Test it. Eg, npm install pretty-diff -g.
In order to be able to run the newly installed software, you'll need to add the install locations to your PATH. You can find these with npm bin -g and npm bin (the -g flag is the "global" installation location).
Not really anything special that you have to do to get it to run in Cygwin (although I can't say if everything works).
Use Console2, it allows you to run create tabs of CLI shells. It seems running cygwin inside console2 allows me to use node REPL just fine. I have no idea why :P
Follow this guide to add cygwin to console2:
http://blog.msbbc.co.uk/2009/11/configuring-console-2-and-bash-with.html
With Bjørn's suggestion (using Console2) and Soyuka's alias (steps here), my node.js v0.10.13 and npm v1.3.2 are now working under Babun v1.02, a Cygwin distribution.
For windows, Just run bash.exe in cmd, so that you could have a bash work around with cmd console directly, which could support ALL NODE WORKING PERFECTLY.
C:\Users\郷>bash
郷#CHIGIX ~
$ node
>
I'm using this wrapper in /usr/local/bin/node (note no extension!)
#!/bin/sh
_cmd="$(cygpath -lw -- "$1" )"
shift
"/proc/cygdrive/C/Program Files/nodejs/node.exe" "$_cmd" "$#"
This is far from perfect, as Node do not understand Cygwin directory tree, but works relatively well with relative names.
From Windows, run Cygwin.bat (instead of Cygwin Terminal) then in that run node: see and reply on this answer on this effectively-same question asked 1.5 years later.
Grab and run the node.js Windows installer.
In the Cygwin prompt type node
See if it works.

Node.JS - How to Run Node Command from any path?

I have installed the latest node.js from here . I see the %Path% variables have been set for Node.js. But, When i run node from C:\ , i get a "Node is not an recognized comman". But node command is working fine from "C:\Program Files (x86)\nodejs" path. Can i not run Node commands from C:\ or Say from an other path if i set the Env variables right? Please help. I am running a Win7 X64.
Thank You,
Faraaz
I had the exact same problem, but in my PATH variable I had: C:\Program Files\nodejs\.
After changing it to C:\Program Files\nodejs I could access it from anywhere.
What happens if you run node --version? I have never tried node.js from windows but if that doesn't work there is something wrong with your paths.
What do you get when you run echo %PATH%?
You should check if the path C:\Program Files (x86)\nodejs is present in your %PATH. If not, add it via the system properties (persistent change). In any case, restart your command prompt, it'll reload the %PATH variable. If you're lucky, it should work now :)
Most likely it happens because there is no Node path in your PATH environment variable.
I see two ways to solve this
Just add Node path into the end of PATH.
Reinstall Node as administrator
run 7-zip (or some file manager) with administrator privileges >>
browse to node-installer.msi >> open it, install node >> enjoy
My Sublime was working with Nodejs fine. I could press Alt-R and see the output from Node in Sublime. Then at some point I upgraded Sublime. I now have version 2.02 build 2221
And at some later point I tried Alt-R and got this infamous message
'node' is not recognized as an internal or external command
But it had worked, so what changed?
The steps I took to fix it were to install git bash and then
$ git clone https://github.com/tanepiper/SublimeText-Nodejs.git
$ cd SublimeText-Nodejs/
$ git checkout 095ba03344
Back in Sublime I clicked Preferences > Browse Packages. This opened up Windows Explorer with the folder:
C:\Users\me\AppData\Roaming\Sublime Text 2\Packages
I replaced the contents of the Nodejs folder with the git version. Re-started Sublime and then Alt-R sprang back into life.
Other things that turned out to be irrelevant were changing the file Nodejs.sublime-settings and tampering with system environment variables. The only thing that worked was 095ba03344 as described here
https://github.com/tanepiper/SublimeText-Nodejs/pull/39

Resources