简体   繁体   中英

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:

来自 npm 安装的警告

Try,

npm cache clear -f 

and,

npm install pm2 -g --unsafe-perm

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM