【问题标题】:Azure deployment fails for Node js application : npm ERR! code EPERMNode js 应用程序的 Azure 部署失败:npm ERR!代码 EPERM
【发布时间】:2021-05-13 18:58:14
【问题描述】:

我正在尝试在 Azure 应用服务上部署节点 js 应用程序。应用程序文件和 node_modules 文件夹按预期创建,但应用程序无法启动并出现以下错误

 2021-02-10T04:22:12.727825432Z npm ERR! code EPERM
2021-02-10T04:22:12.734836329Z npm ERR! syscall lchown
2021-02-10T04:22:12.734870329Z npm ERR! path /home/site/wwwroot/node_modules/istanbul-lib-instrument/node_modules/.bin/semver
2021-02-10T04:22:12.754015919Z npm ERR! errno -1
2021-02-10T04:22:12.754037719Z npm ERR! Error: EPERM: operation not permitted, lchown '/home/site/wwwroot/node_modules/istanbul-lib-instrument/node_modules/.bin/semver'
2021-02-10T04:22:12.754053319Z npm ERR!  [OperationalError: EPERM: operation not permitted, lchown '/home/site/wwwroot/node_modules/istanbul-lib-instrument/node_modules/.bin/semver'] {
2021-02-10T04:22:12.754058419Z npm ERR!   cause: [Error: EPERM: operation not permitted, lchown '/home/site/wwwroot/node_modules/istanbul-lib-instrument/node_modules/.bin/semver'] {
2021-02-10T04:22:12.754062319Z npm ERR!     errno: -1,
2021-02-10T04:22:12.754065719Z npm ERR!     code: 'EPERM',
2021-02-10T04:22:12.754069319Z npm ERR!     syscall: 'lchown',
2021-02-10T04:22:12.754073019Z npm ERR!     path: '/home/site/wwwroot/node_modules/istanbul-lib-instrument/node_modules/.bin/semver'
2021-02-10T04:22:12.754076719Z npm ERR!   },
2021-02-10T04:22:12.754097119Z npm ERR!   errno: -1,
2021-02-10T04:22:12.754100719Z npm ERR!   code: 'EPERM',
2021-02-10T04:22:12.754104319Z npm ERR!   syscall: 'lchown',
2021-02-10T04:22:12.754107819Z npm ERR!   path: '/home/site/wwwroot/node_modules/istanbul-lib-instrument/node_modules/.bin/semver',
2021-02-10T04:22:12.754111519Z npm ERR!   parent: 'istanbul-lib-instrument'
2021-02-10T04:22:12.758140417Z npm ERR! }
2021-02-10T04:22:12.761503315Z npm ERR! 
2021-02-10T04:22:12.762563214Z npm ERR! The operation was rejected by your operating system.
2021-02-10T04:22:12.763983914Z npm ERR! It is likely you do not have the permissions to access this file as the current user
2021-02-10T04:22:12.764467213Z npm ERR! 
2021-02-10T04:22:12.765574713Z npm ERR! If you believe this might be a permissions issue, please double-check the
2021-02-10T04:22:12.769113211Z npm ERR! permissions of the file and its containing directories, or try running
2021-02-10T04:22:12.769133011Z npm ERR! the command again as root/Administrator.

它是基于 Linux 的应用服务。启动命令 - npm install && npm start

节点版本 12. NPM - 6.14

应用程序在第一次部署时工作,但在所有进一步的部署中都失败了

我被困了 2 天。提前致谢

【问题讨论】:

  • 这是我使用 DevOps 部署节点项目发布步骤的答案,你可以看看。 stackoverflow.com/questions/64758494/…
  • 在部署之前通过 npm install 解决了这个问题,并且在应用服务中仅使用 npm start 作为运行命令。多丽丝的评论也很有效。谢谢

标签: node.js azure-devops azure-web-app-service npm-install


【解决方案1】:

我能够通过两种方式解决此问题。

  1. 在 Pipeline 中构建之后,是否安装了 NPM 以包含 node_modules 文件夹并进行部署。 app service start 命令中的 npm start 运行应用程序。

  2. Follow this link 使用了 Doris 建议的链接,一切正常。

【讨论】:

  • 太棒了!感谢您在此处分享您的解决方案,您可以接受它作为答案,这样它可以帮助遇到相同问题的其他社区成员,我们可以归档这个帖子,谢谢。
【解决方案2】:

Node js 应用程序的 Azure 部署失败:npm ERR!代码 EPERM

您可以尝试通过命令行清理 npm 缓存:

npm cache clean --force

如果它不适合您,请手动删除缓存文件。为此,请转到默认 NPM 缓存文件夹并删除其内容:

默认值:~/.npm on linux,或%AppData%/npm-cache Window

然后您可以尝试安装并启动您的应用程序。

注意:

避免使用sudo npm install -g,因为你可能会弄乱 npm 权限。而是将权限更改为 npm 的默认目录,或者将 npm 的默认目录更改为另一个目录。更多细节在这里:https://docs.npmjs.com/getting-started/fixing-npm-permissions

【讨论】:

  • 谢谢你,里奥。我尝试清理缓存并重新安装 npm 包,该问题在第一次部署时已解决,但在进一步部署时继续出现相同的错误。我在构建后再次执行 NPM install 并使用 npm start 作为启动命令而不是 npm install && npm start 在某种程度上设法解决了这个问题
  • @user88,感谢您的回复。那么,你现在解决这个问题了吗?如果是,请您将您的评论转换为答案?这可能有利于其他社区成员阅读答案,避免在已经有答案的帖子上花费大量时间。谢谢。
猜你喜欢
  • 2020-03-15
  • 1970-01-01
  • 2021-06-28
  • 1970-01-01
  • 1970-01-01
  • 2022-01-26
  • 2021-10-23
  • 2023-03-06
  • 1970-01-01
相关资源
最近更新 更多