NPM Package Error- 'newman' is not recognized as an internal or external command - npm

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!

Related

Running a express server from WSL ( UNC paths are not supported )

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.

Environment variables (zsh terminal) installed through npm on MacOS 12.4 Monterey - SOLVED

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).

Visual Studio Code (Windows) Not Detecting Global NPM Modules

I'm experiencing an issue where Visual Studio Code in Windows 10 is not able to detect globally installed NPM packages within the Integrated Terminal.
For example, if the windows command prompt I install #angular/cli via command npm install -g #angular/cli, within that command prompt I can execute #angular/cli commands such as ng --version without error. After that global npm module install, within Visual Studio Code, performing the same ng --version gives me the error:
The term 'ng' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
I can however within the integrated terminal successfully perform commands such as npm -v and node -v.
I have the following items in my system environment variables
C:\Program Files\nodejs\
%AppData%\npm
Are there Visual Studio Code user or system environment variables I'm missing to allow detection of global npm modules?
Thank you for any help you can provide.
Visual Studio Code must be "Run as Administrator" for working Terminal Commands.
I was able to resolve the issue and use global npm commands in Visual Studio Code by modifying my system environment path variables to position %AppData%\npm before %ProgramFiles%\nodejs\ per npm troubleshooting tips
no need to do anything else just follow below steps -
right click on my computer (this pc).
go to properties.
click on advanced system setting.
click on environmental variable.
select path variable from system variable.
click on edit button.
add %AppData%\npm and %ProgramFiles%\nodejs\ at top of the list.
8 click on ok. ok. ok
restart your system.
after restart open visual studio code as run as administrative mode.
Enjoy...............!!!!!
Run Visual studio code as an administrator. Then type ng command. It should work
Reboot your computer , this worked for me
If you have entered the environment variable and it is still not recognized and if you don't want to reboot your computer because you have so many things running then just reboot your Visual Studio Or Visual Studio Code and then Open Terminal (ctrl + `) and run
npm install
Now it will work fine.
You can resolve the issue by opening the VS Code Terminal and type
npm install -g #angular/cli
This should resolve the issue.
Run powershell or cmd prompt in admin mode.
Check if npm and node commands work (if not, then check environment variables as others have mentioned).
Update node using npm [https://stackoverflow.com/questions/18412129/how-can-i-update-
npm-on-windows]
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
Run npm install -g #angular/cli
Run ng --version in Visual Studio Code to see if it's now working.
If you do not have access to Environmental variable (office machines).
You can try to run command like this:
npm run <your angular command>
it works as well, just need to add npm run before ng command
Example -> npm run ng g c shop/cart
I found that adding %AppData%\npm to your Path variable made it work for PowerShell and the Command Prompt, it still did not work for the integrated PowerShell in VS Code for me.
When I changed it from %AppData%\npm to the actual path C:\Users\<USER>\AppData\Roaming\npm where <USER> is your user directory, and reopened VS Code it started working.
Additionaly to all the good advice here, make sure that you have node.js installed on your machine.
To me the solution was adding the extensions for npm:

'npm' is not recognized as an internal or external command, operable program or batch file

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.

running bower from TeamCity (Windows)

I've got a set of build steps in a project (Team City 9.0c)
One of them is running bower install which is a simple command line execution with no parameters.
Bower is installed on the system (I can run it just fine from the command prompt on the machine) but I get the following error
[10:47:35][Step 2/7] Starting: D:\TeamCity\buildAgent\temp\agentTmp\custom_script8385462966123630321.cmd
[10:47:35][Step 2/7] in directory: D:\TeamCity\buildAgent\work\5d43cd6017ab83d4\website\Amaze.Web
[10:47:37][Step 2/7] 'bower' is not recognized as an internal or external command,
[10:47:37][Step 2/7] operable program or batch file.
[10:47:37][Step 2/7] Process exited with code 1
[10:47:37][Step 2/7] Step Bower (Command Line) failed
I've seen this before where PATH is not set to the location of the npm binaries in c:\users\xxxx\roaming\... so the TC user cannot find them, however PATH is correct.
Both npm and grunt work successfully. What could be causing this?
Is the path variable defined a user variable? If so, it should be a system variable which will be used by the TeamCity process.
You haven't written which accounts the build agent runs as.
I had a similar problem and my build agent was running using Local System. I had to create a dedicated windows user account for the teamcity build agent, in the build script I added
npm install -g bower
set path=%path%;c:\path_to_bower_for_this_user;