简体   繁体   English

npm 无法在Windows 10中安装pm2或nodemon

[英]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.当我的文件被更改时,我尝试为自动重启 nodejs 服务器安装一个 nodemon。 But I got two warnings so, I try to install other npm packages like forever or pm2, but I still get the same warning.但是我收到了两个警告,所以我尝试安装其他 npm 软件包,例如 forever 或 pm2,但我仍然收到相同的警告。 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. Windows 10 内置了执行策略,默认情况下会限制任何脚本的执行。 So, you have to set the policy first.因此,您必须先设置策略。

In Powershell (Admin rights), first look at the ExecutionPolicy with command在Powershell(管理员权限)中,先用命令查看ExecutionPolicy

Get-ExecutionPolicy -List Get-ExecutionPolicy -List

'Undefined' policy means scripts like pm2 will be restricted. “未定义”策略意味着像 pm2 这样的脚本将受到限制。 To enable it, run command要启用它,请运行命令

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

Then, try run pm2.然后,尝试运行 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.就我而言,这是 npm 的版本问题:我尝试使用节点版本 17.8.0 和 npm 版本 8.3.1 安装 pm2,但我无法成功。

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.基于 github 上的那个问题: https://github.com/npm/cli/issues/4234 ,将节点版本降级到 16.13.2 和 npm 版本 8.1.2 修复了这个问题。

using nvm:使用 nvm:

nvm install 16.13.2
nvm use 16.13.2
npm install -g pm2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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