How to get jenkins to use current npm version? - node.js

A project I am on has a Jenkins server to which I don't have remote access.
The server admin has installed npm 5.8 using npm install -g npm.
Executing npm -v reports a version of 5.8.
However, during the Jenkins build process, npm -v reports a version of 5.6 which is the version that shipped with the installed version of NodeJS.
Can someone assist me in what I should be asking the admin to change?

The admin should be able to install the Jenkins NodeJS Plugin which allows you to handle several different installations (in different versions) of NodeJS. This way you can address the version of NodeJS & npm you want to use from the Job configuration, as the correct folder is temporarily added to the PATH variable.
There is a walkthrough guide on the wiki page of the plugin.

Following steps will help you:
If it is windows machine, you better to restart the node after you install anything. Then only Jenkins can get the updated environment variables.
Verify the Environment variable pointed to correct version folder.
If you know the updated installed path then you can create local environment variable at job level using following command.
env.NODE_HOME =
"C:\Windows\system32\config\systemprofile\AppData\Roaming\npm"

Related

"No version is set for command npm" .tool-versions file missing

I'm attempting to create my react app in VS code. After installing node.js (V 18.12.1), I ran the code to create my app and recieved the following response:
npm create-react-app example
No version is set for command npm Consider adding one of the following versions in your config file at nodejs 16.15.0 nodejs 16.17.0 nodejs 16.17.1 nodejs 16.18.0 nodejs 16.18.1
I attempted the reinstall node.js and believe the issue may be due to the absence of my .tools-version file, but I don't know how to create it.
You can use this
npx create-react-app example
Can see the detail in official document.
This could be because you are using a version of Node.js that does not include the npm command. In this case, you can try installing the npm command by running the following command:
npm install -g npm
or try these.
Verify that Node.js is installed correctly on your system by running the node -v command in a terminal. This should print the version number of Node.js if it is installed correctly.
Check if the npm command is in your system's PATH by running the
which npm command in a terminal. This should print the full path to the npm executable if it is in your PATH.
If npm is not in your PATH, you can add it by modifying your PATH
environment variable. You can do this by modifying your shell's
profile file (e.g., ~/.bashrc, ~/.bash_profile, etc.), or by adding the path to the npm executable to your PATH manually.
If you have multiple versions of Node.js or npm installed on your
system, you may need to update your PATH to point to the correct
version. Alternatively, you can use a version manager such as nvm
(Node Version Manager) to manage multiple versions of Node.js and
npm on your system.
Try out and see!
Came here searching a very similar error. I had just got setup with a version manager, asdf, and installed NodeJS LTS (asdf install nodejs lts) before running an npx command and getting the error below.
No version is set for command npx
Consider adding one of the following versions in your config file at
nodejs 18.12.1
nodejs lts
There's no path at the end of that second line 🤔 but given the error and asdf instructions on setting a version, I configured a NodeJS version in the global .tool-versions file and that solved my issued:
echo "nodejs lts" >> $HOME/.tool-versions
Manu Jo Varghese has some great suggestions for checking your installation and environment! To add:
which node: find NodeJS program in your path
bash or zsh -> check which shell you're in, then check .bashrc or .zshrc files as fits

Is there a way to install different node version using npm in windows?

Because of our company policies I cannot install nvm on my machine to have multiple node versions. Is there any npm package using which I can install and switch to different versions of node ?
I have a build tool for a proprietary system that needs an old node version.
I just downloaded and unzipped that version into a folder and run a batch script on the console to put the old node as the first %PATH% entry. After running the batch script all node calls use the old version

Azure DevOps self hosted agent reports wrong version for NPM

We have updated Node to version 10.16.3 and NPM to version 6.11.3 (all the latest at this time) on our Windows based self hosted agent.
However, in a job run logs, we see that the agent reports version 6.9.0 for NPM, which is the default version for Node 10.16.3 installation.
Inside the VM where the hosted agent is, if I run 'npm' in the CMD, I get the latest version for NPM. Also, if I run the same command that the agent is running to get the version, I still get the correct version for NPM:
What could be wrong here?
The reason we want the latest version of NPM is because our builds run faster with it.
Thank you!
We have had a very amateur approach to this problem. When we are logging in through RDP, we are using the user 'agent' and all installations are scoped to that user. However, the agent is using the NetworkService user, which has its own scope for NPM and Node.
The fix was basically to add step in our build pipeline to check for latest version of NPM and install it in case it is not installed.
Yeah, I got caught out by this too. Because it runs under the NetworkService account, it can't read the global folder, so has it's own little copy/cache at
C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm
My easiest way to get back up and running, was to just manually upgrade the npm at that location using the following command:
npm install --prefix C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm npm

Angular - How can I specify a different node.js version than what is installed on the system?

System: CENTOS7
I'm working on our TEST system that has a version of node prior to 8.9.
The application which I'm working on uses node 8.9.
The application runs fine when deployed out to Tomcat.
The issue is that I'm unable to just run 'ng serve' because the system sees v6.x.x.
Is there a way that I can modify my project to see the packaged node v8.x so I can run the ng options?
I'm instructed to not modify the system settings.
UPDATE
Just so others know what I ended up doing was modifying my bash script to include in the PATH ./node_modules to where node was in the local project. This is always the same path for whatever project and its version on node.
I did that for a while until a few months ago when we finally had rights to do things differently and are now using Node Version Manager
Install nvm (node version manager) to centOS
Then you will can install many version of node in your system
In this case you have to alias default version of node in nvm setting with version you want

tfs 2017 on site npm build

I am trying to get a npm build of SPA application using the npm build task. I need the task to use the latest Nodejs and NPM, how can I update the binaries of the task? I have installed the Nodejs on the TFS Build machine but the npm task is not using the latest version, it seems there is another version fixed to tfs in some location
Normally you just need to update the Nodejs to the latest version, then the NPM task will call the latest version of Nodejs accordingly.
So, please check if you have installed multiple versions of Nodejs in different directory, If it is, just remove the old one.
And go to your pool settings page: http://server:8080/tfs/_admin/_AgentPool and select your agent, verify that if the Node.exe and NPM are identified as a system capability with the correct path set. If the latest version not existing there, just try to restart the agent service to sync it, if still not be identified, you can try to add it manually. Then try it again.

Resources