Azure DevOps self hosted agent reports wrong version for NPM - node.js

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

Related

azure app services running with old version of NPM

I have an azure app-services as node v14, however, the app-services pre-install NPM as version 6.14
Then I try to upgrade to the latest on SSH as:
sudo npm install -g npm#latest
but didn't work. Any ideas??? How we can update this?
Or is not possible?
I also spent hours trying to upgrade node from Kudu as well. Here's what worked for me.
From Azure Portal, enter the applicable App Service blade. Inside Settings -> Configuration there is an Application settings tab with a
Name: WEBSITE_NODE_DEFAULT_VERSION.
Value: Hidden value... (click on it -> Advanced edit)
I changed the version to 16.13.0
The app service restarted and with node 16.13.0.
We have tested in our environment , by creating a webapp with runtime stack as NodeJS , operating system as windows.
we are able to upgrade the Nodejs version in kudu by adding the application setting.
WEBSITE_NODE_DEFAULT_VERSION:<supportednodejsVersion Value>
you can get the supported NodeJS version value by routing to the below path of your web site
https://<yourwebappname>.scm.azurewebsites.net/api/diagnostics/runtime
Here is the reference output :
Here is the reference SO threads.
For Windows, additional steps are required. To make things easy, you can use the npm-windows-upgrade package.
Open Powershell as administrator
Execute Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
Execute npm install -g npm-windows-upgrade
Execute npm-windows-upgrade
Use the up/down arrows to select the correct NPM version.
After executing the above steps, you can see that now the correct version of NPM has been installed by executing npm -v.
If it is not possible to install the updated version in your environment, a workaround would be to use npx to invoke the latest npm like this:
npx -p npm#latest npm
So, instead of running npm install or npm ci, you could run npx -p npm#latest npm install or npx -p npm#latest npm ci.
That workaround aside, I don't know much about Azure App Service specifically, but if you can run command -v npm, that should give you the path where npm is installed. From there, you may be able to tell what might be the problem. (One thing worth trying if you haven't yet is to run npm install -g npm#latest without sudo. Using sudo with npm is a bit of an anti-pattern and someone may have taken steps to thwart it.)

Node app in Azure App Service npm install timeout even for single packages no matter what, extremely unreliable

I have a standard Azure App Service and I'm trying to run a node rest api from it. I've had nothing but troubles from the very start.
Going into kudu to check what node versions are supported, the only supported node version listed is "nodejs":[{"version":"0.10.40" but I added the env variable where I specified node version 8.4 and it seems to be supported and when I run node --version it gives me 8.4 but that kudu config hasn't changed.
For some reason -- it doesn't install the packages right, I looked for 'body-parser' in the node_modules folder and it is not there even if its listed in package.json as direct dependency.
Running npm install or npm install body-parser all time-out with no real reason.
Running npm install as part of the devops release deployment cycle runs in 17 secondsbut it ends up saying 'up to date'
Judging by the mismatches between kudu's runtime file, the node version mismatch I think there's something seriously wrong with my app's config.
I'm running off a pay-as-you-go subscription using the Basic tier with 100 units.
This is a freshly installed app powering absolutely nothing.
First, please make sure that you have set the WEBSITE_NODE_DEFAULT_VERSION value in tab Application settings tab of your WebApp on Azure portal to enable the Node version what you want, as the figure below to use Node version 10.14.1.
Then, you can check it via commands node -v & npm -v in Kudu console.
I tried to install body-parser package in the directory node-test created by me via command npm install body-parser. Although there is some warn messages due to missing some files like package.json, the body-parser package has existed under the node-modules.

changing teamcity agent npm version

I'm trying to point teamcity to use the latest npm version 6.0.1. but for some reason, it is stuck using 5.6.0.
node.js 10.1.0
node.js.npm 5.6.0
the node version gets updated.
I have tried adding npm i npm#latest -g to the build step, it runs successfully, but the teamcity agent version doesn't change.
You must first find out where node & npm are installed at the system level. Using the usual way to upgrade npm i npm#latest -g will install npm into your user profile, it won't update that system-level installation (which is what TeamCity's build agent uses).
On my (Windows) build agent I found it at C:\nodejs but your box may vary
Open a command prompt, cd to that directory and then use npm i npm#latest (note no -g switch). This will upgrade your system-level npm installation (used by the build agent). You will likely need administrative rights to the box etc etc.
To solve this issue, i change the Teamcity server and agent services users from Local System to an actual User.
Login into the build server as the user and Installed npm and node. Did a server restart.
Now TC using the latest version of npm.

How to get jenkins to use current npm version?

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"

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