无法在 Ubuntu 20.4 服务器上运行 npm install

Posted

技术标签:

【中文标题】无法在 Ubuntu 20.4 服务器上运行 npm install【英文标题】:Can't run npm install on Ubuntu 20.4 server 【发布时间】:2022-01-18 17:46:13 【问题描述】:

我有一个 node.js 应用程序,我想在 Ubuntu 20.4 服务器上运行,当我尝试运行命令 npm install 时,我看到以下错误,我在服务器上没有 root 访问权限,这在哪里可以问题是?我有 6.14.3 版本的 npm 和 14.15.3 版本,我该如何处理这个问题?

```
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

> core-js@2.6.12 postinstall /var/www/site/public_html/node_modules/@nuxt/babel-preset-app/node_modules/core-js
> node -e "tryrequire('./postinstall')catch(e)"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling javascript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js@3.10.2 postinstall /var/www/site/public_html/node_modules/core-js
> node -e "tryrequire('./postinstall')catch(e)"


> bootstrap-vue@2.21.2 postinstall /var/www/site/public_html/node_modules/bootstrap-vue
> opencollective || exit 0

sh: 1: opencollective: Permission denied

> nuxt@2.15.4 postinstall /var/www/site/public_html/node_modules/nuxt
> opencollective || exit 0

sh: 1: opencollective: Permission denied

> swiper@5.4.5 postinstall /var/www/site/public_html/node_modules/swiper
> echo "Love Swiper? Support Vladimir's work by donating or pledging on patreon:
 > https://patreon.com/vladimirkharlampidi
"

Love Swiper? Support Vladimir's work by donating or pledging on patreon:
 > https://patreon.com/vladimirkharlampidi

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted "os":"darwin","arch":"any" (current: "os":"linux","arch":"x64")
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted "os":"darwin","arch":"any" (current: "os":"linux","arch":"x64")

added 1334 packages from 697 contributors and audited 1338 packages in 17.59s

102 packages are looking for funding
  run `npm fund` for details

found 58 vulnerabilities (39 moderate, 18 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details
```

【问题讨论】:

【参考方案1】:

这可能是权限问题 试试这个

sudo npm cache clean 
sudo npm install

【讨论】:

以上是关于无法在 Ubuntu 20.4 服务器上运行 npm install的主要内容,如果未能解决你的问题,请参考以下文章

RIDE 工具无法在 Ubuntu 20.4 上安装

在 Ubuntu 20.4 上使用 postgresql 设置的 Django cookiecutter 无法迁移

统信UOS(ubuntu20.4)+B525 linux上使用摄像头

Ubuntu 20.4 LTS 安装SecureCRT

ubuntu 20.4 安装msyql+创建mysql用户

centos8及Ubuntu20.4安装docker教程