azure app services running with old version of NPM

Viewed 480

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?

4 Answers

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 :

enter image description here

Here is the reference SO threads.

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

For Windows, additional steps are required. To make things easy, you can use the npm-windows-upgrade package.

  1. Open Powershell as administrator
  2. Execute Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
  3. Execute npm install -g npm-windows-upgrade
  4. Execute npm-windows-upgrade
  5. 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.

Related