azure app services running with old version of NPM - azure

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

Related

Unable to upgrade to latest version of npm after installing recent Node version [duplicate]

This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
I tried this:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
...but it didn't work.
How do I do this on Windows?
Note: The question is specifically asking how to upgrade npm, not Node.js. If you want to update Node.js over a CLI on windows, I recommend running winget upgrade -q NodeJS or use chocolatey for that.
What method should I choose to update NPM?
Node.js v16 or higher?
npm install -g npm
Node.js v14 or below?
Consider updating to latest LTS release of Node.js
npm-windows-upgrade
Upgrade with npm-windows-upgrade
Run PowerShell as Administrator
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
Note: if you run the Node.js installer, it will replace the Node.js version.
Upgrades npm in-place, where Node.js installed it.
Does not modify the default path.
Does not change the default global package location.
Allows easy upgrades and downgrades and to install a specific version.
A list of versions matched between NPM and Node.js (https://nodejs.org/en/download/releases/) - but you will need to download the Node.js installer and run that to update Node.js (https://nodejs.org/en/)
Upgrade with npm
npm install -g npm
Note: some users still report issues updating npm with npm, but I haven't had that experience with v16+.
Download and run the latest MSI. The MSI will update your installed node and npm.
To update NPM, this worked for me:
Navigate in your shell to your node installation directory, eg C:\Program Files (x86)\nodejs
run npm install npm (no -g option)
Like some people, I needed to combine multiple answers, and I also needed to set a proxy.
This should work for anyone. I have zero desire to run an EXE file or MSI file .. uninstall/ reinstall, or manually delete files and folders. That is so 1999 :P
Run this to update NPM:
Run PowerShell as administrator
npm i -g npm // This works
I am not thinking this code actually upgrades your npm version below
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
(courtesy of "Robert" answer)
Run this to update Node.js:
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files (x86)\nodejs\node.exe' (courtesy of BrunoLM answer)
If you get `wget : Could not find a part of the path .... "**, see below ...scroll down. Reading Web Response... It's at least punching through the firewall /proxy (if you have one or have already ran the code get through ...
Otherwise
You might need to set your proxy
npm config set proxy "http://proxy.yourcorp.com:811" (yes, use quotes)
2 possible errors
It cannot find path of the path solution "where.exe node" (courtesy of Lonnie Best Answer)
E.g. if Node.js is NOT living in "Program Files (x86)" perhaps with where.exe, it is living in 'C:\Program Files\nodejs\node.exe'.
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'
Now perhaps it tries to upgrade but you get another error, "node.exe is being used by another process."
Close /shutdown other consoles .. command prompts and PowerShell windows, etc. Even if you're using npm in a command prompt, close it.
npm -v (3.10.8)
node -v ( v6.6.0)
DONE. I'm at the version that I want.
You can update your npm to the latest stable version with the following command:
npm install npm#latest -g
Use PowerShell to run it. This command doesn't need windows administrator privileges and you can verify the result with npm -v
You can use Chocolatey which is a package manager for windows (like apt-get for Debian Linux).
Install fresh (you might need to uninstall previously installed versions)
> choco install nodejs
Update to the latest version
> choco update nodejs
and for npm
> choco update npm
The previous answers will work installing a new version of Node.js (probably the best option), but if you have a dependency on a specific Node.js version then the following will work: "npm install npm -g". Verify by running npm -v before and after the command.
This works fine for me to update npm on Windows 7 x64:
Windows start
All Programs
Node.js
Node.js command prompt (alternative click)
Run as administrator
$ npm -g install npm
remove C:\Program Files\nodejs\npm.cmd the new npm will be at C:\Users\username\appdata\roaming\npm\npm.cmd
Hope this helps.
Open PowerShell as administrator.
To install a first time you can use this small script to download the latest msi and run it
$nodeLatest=((curl https://nodejs.org/download/release/latest/).Content | findstr x64.msi) -replace "<(.*?)>", "" -replace "\s+.+", "";
wget "https://nodejs.org/download/release/latest/$nodeLatest" -OutFile (join-path $env:TEMP node.msi); Start-Process (join-path $env:TEMP node.msi)
On future upgrades you can download just node.exe and update npm with
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'
npm i -g npm
You should now have the latest node and npm.
I went a little further and decided to implement a nvm for Windows.
https://github.com/brunolm/nvm
Install-Module -Name power-nvm
nvm install latest
nvm default latest
1. Installing latest npm version
npm install –g npm#latest
(You can type "npm –version" to check that)
2. Installing Node
a. Install node new version via following URL: https://nodejs.org/en/download/current/
Follow the default choices
b. Remove C:\Users\\AppData\Roaming\NPM
c. Remove C:\Users\\AppData\Roaming\npm-cache
Optionally:
d. (Delete node_modules folder in your current project folder)
e. npm cache verify
f. npm install
Use Upgrade npm on Windows
This is the official document for a user to upgrade npm on Windows!
Here is my screenshot!
For what it's worth, I had to combine several answers...
Uninstall Node.js in control panel Add/remove programs.
Delete directories, both C:\Program Files (x86)\nodejs\ and C:\Program Files\nodejs\ if they exist.
Install the latest version, http://nodejs.org/download/
How to Update Node.js:
Uninstall Node.js. Click the Start menu, type "Change or Remove a Program", click on the item shown, find Node.js in the list and uninstall it.
Delete directories, both C:\Program Files (x86)\nodejs\ and C:\Program Files\nodejs\ if they exist.
Install the latest, https://nodejs.org/en/download
The uninstall/delete/install seems unnecessary, but it often is and this will save your time.
These instructions come from Microsoft.
How to Update NPM:
https://www.npmjs.com/package/npm-windows-upgrade
This is the official documentation for upgrading npm on windows.
All was tested and working on Windows 10 (2017).
this is best tool to maintain version of NODE.Js i NVM
Node Version Manager (nvm) for Windows
but for Windows, with an installer. Download Now! This has always been a node version manager, not an io.js manager, so there is no back-support for io.js. However, node 4+ is supported.
For me, after totally uninstalling node 10.29, and then installing node 4.2.2, there remained a 10.29 node.exe file in my c:\windows folder.
I found this by using the following command:
where.exe node
The command returned:
C:\Windows\node.exe
C:\Program Files\nodejs\node.exe
So even though I had successfully installed version 4.2.2 via the msi executable, the command node -v would continue to report I was running version 10.29.
I resolved the problem by deleting this file:
C:\Windows\node.exe
Thereafter, node -v reported the upgraded version instead of the unwanted remnants of the prior version.
For NodeJS
Download required node version msi from here and install
for Npm
Run PowerShell as Administrator
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
This works fine for me
Run Command Prompt as Administrator
Navigate to the folder containing nodejs (eg. C:\Program Files\nodejs)
Run Powershell -ExecutionPolicy Unrestricted
Run npm-windows-upgrade
This will show list of versions available to install. Just select your desired version by moving up/down key & Press Enter.
This'll update your npm
To check the current version of npm
Run npm --version
Command Prompt Screenshot
I was also facing similar issues. I followed below mentioned steps and it worked for me:
go to Windows > Start > Node.js
right click on Node.js command prompt
click on Run as administrator
ping registry.npmjs.org
npm view npm version
cd %ProgramFiles%\nodejs
npm install npm#latest
and npm updated successfully. Earlier I was trying for CMD and that was throwing error. may be some path issue that got resolved by running NodeJs Command Prompt. hope it'll work for you. try this.
OK guys, I read (tried on Windows) all the previous stuff and all of these answers have their own disadvantages.
For the best way to update Node.js (at least for me), go to https://nodejs.org/en/
Then download the last version and install it in same folder you installed the previous version in - 1 min and it's done. You don't need to remove any old files.
Then update npm typing in cmd: npm install --save latest-version
To install the updates, just download the installer from the Nodejs.org site and run it again. The new version of Node.js and NPM will replace the older versions.
The easiest way I found so far to update Node.js is using Chocolatey.
Use Chocolatey to install or update the latest version of Node.js on Windows:
Step 1: First, ensure that you already have Chocolatey installed. If not, use an administrative shell to install chocolatey through cmd.exe or PowerShell.exe. For more information, visit: https://chocolatey.org/docs/installation
Step 2: Install with cmd.exe. Run the following command:
#"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
To install with PowerShell.exe, visit: https://chocolatey.org/docs/installation
Step 3: Install or Update with following commands on cmd.exe (on administrative mode)
To Install Node.js: cinst nodejs.install
To Update Node.js: cup nodejs.install
follow these steps for window 10 or window 8
press WIN + R and type cmd and enter
npm i -g npm#next
npm i -g npm#next OR npm i -g node#{version}
Remove environment path C:\Program Files\nodejs from envrionment variable PATH.
type refreshenv in cmd
Now you will have your new version which you installed.
Note: If you don't remove path. You will see the previous version of node.
PowerShell does not execute npm directly, so I suggest using
.\npm install -g npm-windows-upgrade
.\npm-windows-upgrade
And it failed with:
You wanted to install npm 6.1.0, but the installed version is 3.10.10.
A common reason is an attempted "npm install npm" or "npm upgrade npm". As of today, the only solution is to completely uninstall and then reinstall Node.js. For a small tutorial, please see http://aka.ms/fix-npm-upgrade (dead link).
Please consider reporting your trouble to npm-windows-upgrade.
I followed josh3737 and installed the latest MSI from the Node.js homepage.
But I had the additional problem that I still had the old version of Node.js and npm on the command line. The problem was caused by the new installation, and that it was installed into
C:\Program Files (x86)\nodejs\
instead of the previous installation in
C:\Program Files\nodejs\
The new installation added the new directory into my path variable after the old one. So the old installation was still the active one in the path. After removing C:\Program Files\nodejs\ from system path and C:\Users\...\AppData\Roaming\npm from user path and restarting the command line the new installation was active.
Maybe the least path was a local problem that has nothing to do with the new installation. I had two links to AppData\Roaming\npm in it. And maybe this can also be fixed by first uninstalling Node.js and installing the new version afterwards.
You can use these commands:
npm cache clean
npm update -g [package....]
If you are upgrading from a previous version of node, then you will want to update all existing global packages.
You can also specify the package name to be updated.
This might help someone. Neither "npm-windows-upgrade" nor the installer alone did it for me. Powershell was still using an older version of node and npm.
So this is what I did (worked for me):
1. Download the latest installer from nodejs.org. Install node. It will update your node; everywhere (Powershell, cmd etc.).
2. Install the npm-windows-upgrade package (npm install -g npm-windows-upgrade) and run npm-windows-upgrade.
I didn't uninstall anything and didn't set any paths.
In my case, I discovered that I had two copies of Node.js installed. One under "C:\Program Files\nodejs" and another under "C:\Program Files (x86)\nodejs".
This is what worked for me.
Open a local folder other than the one in which nodejs is installed.
Install npm in that folder with command npm install npm
Navigate to the folder containing node js. (C:\Program Files\nodejs\node_modules)
Delete the npm folder and replace it with the npm and bin folders in the local folder.
Run npm -v. Now you would get updated version for npm.
Note: I tried installing npm directly in "C:\Program Files\nodejs\node_modules" but it created errors.
Start
Search for windows powershell
Right click and run as administrator
Type: where.exe node (returns the path of node.exe in your system. Copy this)
wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'PATH-OF-NODE.EXE_WHICH_YOU_COPIED_JUST_NOW'
To check if it has worked, go to your Git bash/Normal command prompt and type: node -v
Here you can find the current version of node: https://nodejs.org/en/blog/release/

How can I update npm, node version on Windows?

I am working on a finance project but now we start a new one here node version issue is getting, how to prevent this issue
You need to install new version on your machine go to this website and install whatever version you needed.
You can refer this as well
Update Npm on windows
Run PowerShell as Administrator
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
Note: Do not run npm i -g npm. Instead use npm-windows-upgrade to update npm going forward. Also if you run the NodeJS installer, it will replace the node version.
you should try
https://github.com/coreybutler/nvm-windows
As you can manage node versions seamlessly with nvm

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.

Not able to install #angular/cli using npm

I am new to "#angular/cli", I have tried every thing but could not install.
I am tired now please some one can help me to install angular 4 "#angular/cli" in my system.
node and npm Version
and when I am installing "npm install -g #angular/cli" then getting
after installing node -v 6 I am getting below erorr
please suggest me where actually I am wrong.
My friend,
Please try: npm cache clean --force. Maybe your npm cache got confused.
It could be issue with your node version. I will suggest you to reinstall node and try it again.
Or you can also try to clean node cache of using npm cache clean --force
List of Npm registry
https://registry.npmjs.org/ (Dfault One)
https://r.cnpmjs.org/
https://registry.npm.taobao.org/
https://registry.nodejitsu.com/
https://skimdb.npmjs.com/registry
To switch just type
npm config set registry "https://registry.npmjs.org/"
Replace the registry url with the above urls check which one works for you.
I am from india so i used https://r.cnpmjs.org/ and the same error got resolved.
Note: Please use npm cache clear (To clear cache ) and npm cache verify (To verify its clear or not), This Method works for me
Changing Registry location worked for me .
Using :
npm config set registry "https://registry.npmjs.org/"
few warnings but meh! life's too short for warnings.(Every thing is working fine BTW)
It is possible your npm cache has a corrupted file, perhaps it partially downloaded something and then got an error. Try npm cache clean --force and see if that helps.
If that doesn't help look in the log file given in the error message. Find the unexpected end of JSON input message in the log file and look before it to see if there are any other hints to the problem.
You updated your question with a new error message. That one is more specific about the corrupted file. Try removing the cli-1.5.5.tgz file from the path specified and try again. If you are using a web proxy on your network then it is also possible that your proxy has stored a corrupted cache: if you are able then turn off any proxies configured for your system and try a direct download.
Perhaps you are missing space- npm install -g #angular/cli#latest
1) Install node.js and check and node -v in command prompt. (Node.js
through website).
2) npm install -g #angular/cli#latest (run in command prompt).
Refer this link for further help
https://github.com/angular/angular-cli
3) Check node -version
4) Check npm -version
5) check ng -version
If already installed, then uninstall it and install again,
npm uninstall -g #angular/cli
npm cache clean
Both the CLI and generated project have dependencies that require Node 6.9.0 or higher, together with NPM 3 or higher.
Try using different Node version.
First try updating NodeJS(8.9.3) and npm(5.6.0). These are the LTS versions. For Node this can be important! If that doesn't work, follow this installation guide for windows.
Make sure you are not connected to VPN while installation is on.
Also, please cleanup your node_modules folder before your next try. I use the command rimraf node_modules to remove this directory in windows.
Lastly try running npm install -g #angular/cli#latest
run npm install -g #angular/cli#latest in command prompt as an admin.
right click the windows button, click on command propmt (Admin) or windows power shell(Admin) depending on your windows version. Then type the command and run it.
Most times, you could get issues when you want to install as a normal user considering the fact that you are using the -g (global) flag.
We too have the same kind of issue with user login then we tried from Administrator login its worked for us. Please do the same it may fix for you too.
Please try running:
rm -rf node_modules package-lock.json
And this,
npm install
If it still does not work, try to manually install cli:
npm install --save-dev #angular/cli
When an npm package is published, the publishing process generates a checksum that npm uses at install time to verify that the package didn't get corrupted in transit.
I had the exact same problem, while i was working in a client site, so the problem could be not your environment, they may have a proxy that needs to be configured, in my case we had a nexus server we were going through, and it has something wrong, but when i started using npm registry directly everything worked fine, but most of the time it's a cache problem, to be sure of that you should run:
npm doctor
you will probably find where is the issue.
if not please post the result maybe i can help.
Make sure your console is running as Admin,
Reinstall node & npm
Reinstall angular/cli
Most probable issue is with npm cache. Just clean your npm cache by command
npm cache clean --force
It should work well.
Uninstall your node package. And try the following
Install the latest node package from
https://nodejs.org/en/download/
Check your node and npm version by
node -v
npm -v
Now install the Angular latest version by
npm install -g #angular/cli
Check the angular version by
ng v
Now start creating your application from
https://angular.io/guide/quickstart
So I'm working with Hyperledger which requires you to have a certain Node version 8 and therefore you cannot use the newest angular installation. Perhaps I can recommend another alternative?
cd into the directory
npm install
npm start
You can also clean your npm cache but if one way doesn't work, try the other.
Try navigating to /usr/local/bin and :
if check if the file named ng is present over there, if yes then
rm -r ng and it will remove that file.
Then you can try sudo npm i -g #angular/cli#latest
And it will be a successful install.
(Writing this for those who might also face this issue in future)
Npm cache clean --force
Then install npm
Then go for angular
Npm I -g #angular/cli
was having a similar issue while installing angular cli using npm.
this was resolved by running:
npm cache clean --force
It happened to me once, looked like I had to specify the version of angular cli:
https://github.com/angular/angular-cli/issues/11589
e.g.:
npm install -g #angular/cli#1.5.0
It could be issue with your node version. I will suggest you to reinstall node and try it again.
Or you can also try to clean node cache of using npm cache clean --force
Please check this also Perhaps you are missing space- npm install -g #angular/cli#latest

npm cannot install pm2 or nodemon in Windows 10

I try to install a nodemon for the auto-restart nodejs server when my file has been changed. But I got two warnings so, I try to install other npm packages like forever or pm2, but I still get the same warning.
Here is my warning capture:
Windows 10 has execution policy built in that restrict any script execution by default. So, you have to set the policy first.
In Powershell (Admin rights), first look at the ExecutionPolicy with command
Get-ExecutionPolicy -List
'Undefined' policy means scripts like pm2 will be restricted. To enable it, run command
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
Then, try run pm2.
Try,
npm cache clear -f
and,
npm install pm2 -g --unsafe-perm
Well it is an old question but since this is the first result on google and the above solutions did not work for me, I will share my solution.
In my case it was a version issue with npm:
I try to install pm2 with node version 17.8.0 and npm version 8.3.1 but I can not made it.
Based on that issue on github: https://github.com/npm/cli/issues/4234,
downgrade node version to 16.13.2 and npm version 8.1.2 fix the problem.
using nvm:
nvm install 16.13.2
nvm use 16.13.2
npm install -g pm2

Resources