I'am trying to run a express server from a WSL terminal in VS Code.
However, whenever, I run the command npm run dev I get the following error:
'\\wsl$\Ubuntu\home\simao\legalize-backend'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
I assume it has something to do with the path from windows to the folder in the WSL directory.
Which one is the right path format or what should I do to make this one valid ?
Searching I found that you can
You can solve this problem(UNC Paths not supported) by mapping a
normal drive letter to the path that has the UNC path.
But how do i map a normal drive letter to the path ?
This happens because whatever tool you are using is trying to run commands via cmd.exe and cmd.exe does not understand UNC paths (those starting with \\... rather than drive letter). Mapping UNC path to drive will convert it to drive letter path.
To map WSL path to Windows drive run cmd.exe (Command Line) and type following command:
net use X: \\wsl$\Ubuntu\home\simao
Where X: is drive that will be created (you'll see it as network drive in e.g. My Computer) and \\wsl$\Ubuntu\home\simao is WSL path to root of that drive. wsl$ is special hostname that tells Windows to connect to WSL, Ubuntu is distribution name under WSL, then finally \home\simao is path to directory in Ubuntu distribution that should be mapped.
I confronted the same situation yesterday. I assume maybe it was something wrong with my npm. Then I checked the npm path with which npm, and I found that my npm was mounted D:\nodejs\npm in Windows (exactly /mnt/d/nodejs/npm in screen).
I guess WSL uses CMD.exe to start npm from Windows described in CMD.EXE was started with the above path as the current directory.
So maybe I can just install a new npm in WSL to solve this. Node Version Manager (nvm), is the most popular way to install multiple versions of Node.js. And each version of nodejs has its own version of npm. Just follow the link below.
Install nvm, node.js, and npm
Plus, if you have Permission denied, use npm uninstall xxx to remove your dependencies you've installed, and install your dependencies again.
Related
Background:
Dear Stackoverflow community. I recently switched from Windows to MacOS and am at a loss how to configure environment variables. Many of the previous questions asked here are about bash instead of zsh.
Goal:
I am trying to install an npm package globally. For instance:
npm install -g vercel
or any other package, and use it in my Visual Studio Code terminal (also zsh). If I want to deploy code I have to use 'npx vercel deploy' every time. I want to be able to use "vercel deploy" but instead I get:
zsh: command not found: vercel
What I tried so far:
Installing the package in zsh and visual studio code terminals (didn't work)
Setting the path equal on both VS and terminal: export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I learned that you need to add environment variabels to a .zshrc file. I don't seem to have a zshrc file. When I do:
sudo ~/.zshrc
Password: XXXXXX
sudo: /Users/vincent/.zshrc: command not found
I am getting another error.
I read in the zsh man file that you should use $HOME/.zshrc instead. Again I am getting the same errors:
vincent#Vincents-MacBook-Air-2 ~ % $HOME/.zshrc
zsh: permission denied: /Users/vincent/.zshrc
vincent#Vincents-MacBook-Air-2 ~ % sudo $HOME/.zshrc
sudo: /Users/vincent/.zshrc: command not found
Update 1:
#slebetman Thank you for your explanation. When I open the terminal I go to home via "cd $HOME" which puts me in in the home directory. However there is no way for me to create a .zshrc file in that directory. Neither via touch or vs code. I am getting the following error: "Unable to write file '/home/.zshrc' (Unknown (FileSystemError): Error: ENOTSUP: operation not supported on socket, open '/home/.zshrc')"
Update 2:
I did manage to find the .zshrc file in visual studio code under /etc. I hope this will work. I was able to overwrite the file with Sudo and add environment variables to it.
Add this to the file .zshrc file under /etc and force overwrite it:
export vercel=/Users/vincent/.npm-global/bin/vercel
Screenshots below for those who will try in the future:
Image with .zshrc file layout
Final remarks:
I don't understand how it is so difficult to add environment variables on Mac while everything else is so easy.
I have read many different questions on stackoverflow, and I can't seem to solve it. Also since I am a newbie I am not allowed to comment on there so I post here in the hope that anyone can help me :)
Best,
Vincent
Note that when you do:
npx vercel deploy
Npm will execute vercel for you without installing it. It does that by temporarily downloading vercel. If you want to run vercel directly without using npx then simply don't use npx. Install it instead:
npm install -g vercel
The -g flag installs the module globally and if the module has a CLI it will be available globally as well (note that depending on your setup you may need admin/sudo privileges to use the -g flag). Now you can run vercel by simply typing:
vercel deploy
This works in all operating systems supported by node.js and npm. That means you can even do this in Windows. In fact I use npm to distribute my tools in a simple cross-platform way so I don't have to support multiple package managers like chocolatey (Windows), homebrew (Mac OS), deb (Debian based distros), rpm (Redhat based distros) etc. (npm does not require your software to be written in node.js - I have published packages on npm written in tcl and bash).
Good evening,
I tried installing sails, yo, gulp & bower via the usual methods of npm i -g yo gulp bower etc but each time I open the terminal to run the command I always get the -bash: sails: command not found error.
I listed all my folders at the root of my folder and found the following:
The contents of the .npm-global/bin/ is actually all the packages I'm trying to use at the command line.
I decided to manual add the bin folder to the .bash_profile so it's contents was the following:
# Setting PATH for Python 3.7
# The original version is saved in su
export PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH="/.npm-global/bin:${PATH}"
but that didn't work either.
Here's where I think the problem first arose - I think that the python install overrode all the previous paths in the file (or moved them somewhere perhaps?) so that all previous terminal commands now don't work.
The usual global install for node packages (/usr/local/lib/node_modules/npm/bin) contains the following:
What am I misunderstanding here & how can I fix this?
I have installed the latest version of Newman (3.10.0) in my 64-Bit Win 10 Machine.
C:\Users\ABC>npm install -g newman
C:\Users\ABC\AppData\Roaming\npm\newman -> C:\Users\ABC\AppData\Roaming\npm\node_modules\newman\bin\newman.js
+ newman#3.10.0
added 195 packages in 57.852s
However, I am not able to use the newman and I am getting below error while accessing.
C:\Users\ABC>newman -h
'newman' is not recognized as an internal or external command,
operable program or batch file.
I have added an environment variable for the NODE_PATH pointing to the newman directory C:\Users\ABC\AppData\Roaming\npm\node_modules\newman
but no luck. Could some one please help.
Adding in the Path variable under Environment Variable solve the problem even if we don't add in NODE_PATH
C:\Users\ yourusername \AppData\Roaming\npm
After doing this reopen command prompt
The issue was fixed after troubleshooting with the Node Application. A previous version of Node (32-bit) was installed in my machine and it was not completely removed after I did an uninstall. When I installed Node 64-Bit both entry was present in the environment variable and caused a conflict.
When I manually deleted both installation folder and the env variable the newman worked correcly.
I have installed node, vc redist and newman once (on clear windows 7 64 bit) and the issue is looks like related to wrong newman installation. Both newman and node should be installed from administrator session (not just with admin privileges). I have installed newman from regular user, system path setting are correct, but user environment was not set:
path=C:\Users\gagarin\AppData\Roaming\npm
So I have copied
C:\Users\<regular_user>\AppData\Roaming\npm
to C:\Users\admin\AppData\Roaming\npm and run C:\Users\admin\AppData\Roaming\npm\newman.cmd from administrator session. After that newman command became work in admin session. Sadly it works in regular user session only if I type full path to newman like
Blockquote
c:> C:\Users\admin\AppData\Roaming\npm\newman run ....
I was also getting the same error and I have followed the below steps to troubleshoot it-
1. Know what user is running jenkins, a simple way is Create a jenkins job and in its Build section run the command
whoami
2. If it shows System user, then do the following-
2.a. Set C:\Users\I823285\AppData\Roaming\npm and C:\Users\I823285\AppData\Roaming\npm\node_modules\newman\bin in SYSTEM ENV. VARIABLES.
b. Restart Jenkins by running CMD as ADMIN, and go to Jenkins installation folder, then enter jenkins.exe restart.
c. Re-build the project
SUCCESSFUL!
I'm getting:
'npm' is not recognized as an internal or external command, operable program or batch file.
when I issue:
npm install -g bower polyserve
Even though I have downloaded node.
I think you have not defined the path of nodejs in Environment Variables on the System Properties.
Add ;C:\Program Files\nodejs\ (path of your nodejs installed directory)
To the end of your Path variable on the "User variable" section of the Environment Variables on the System Properties.
Then reopen cmd prompt and type npm again.It should work now.Hope it helps.
You can do one more thing if still it does not work.Reboot your machine after installing node.
Set path for node.js in your environment variables.
To do this:
right click on MyComputer->properties->advance system setting-> Environment variables-> select & edit "Path" variable in System variables.
Add C:\Program Files\nodejs\; in path
Restart your command prompt
Type node --version in a new console window, the version number should appear as a response.
I would recommend using https://github.com/coreybutler/nvm-windows instead of directly installing a version of node, as it is common to switch between node versions for different projects. Following are the instructions to set it up.
Open PowerShell with 'Run as Administrator' option (Admin role is required for creating symlink)
Check if nvm is installed:
nvm version
If not, follow instructions on https://github.com/coreybutler/nvm-windows#node-version-manager-nvm-for-windows to install it.
If nvm was installed, check if nodejs is in system path:
$Env:Path
If nodejs (likely 'C:\Program Files\nodejs') is not in the path and 'nodejs' symlink file exists in the directory 'C:\Program Files', then add it to the path as described by Vikas Sharma.
If 'C:\Program Files\nodejs' is in the path and symlink file doesn't exists in the directory, list installed node versions using:
nvm ls
Then create the symlink using (needs Admin role):
nvm use <node version>
Check if npm is working now:
npm --version
I had the same issue. Environment variables were all in place (as suggested by the user above). I was using node 8.9.4. Changing node version to 8.16.0 worked for me.
If node is there but npm only not found (which is my case), then
if you have the downloaded node.js in your (windows) pc run the repair option it will do the rest.
Close the cmd window and reopen and test it by running the command
npm -v
Now it will show you the npm version.
I was able to install cordova originally but I am now unable to use it.
I have uninstalled using npm uninstall -g cordova, and this seems to be working as expected. When I attempt to reinstall it using the command npm install -g cordova, the installation seems to run, but when attempting to run cordova commands I get the cordova is not a recognized internal or external batch command message. This is on a Windows 7 Pro x64 machine. What could be the possible causes and fixes for this?
Do you already had the apacha ant ready? If not, try to download that from apache.org and put the patch folder where you extract this to your path variable.
You should add the cordova installation path folder to you path environment variables