首页 > 解决方案 > Node js 应用程序的 Azure 部署失败:npm ERR!代码 EPERM

问题描述

我正在尝试在 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

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

我被困在这两天了。提前致谢

标签: node.jsazure-devopsazure-web-app-servicenpm-install

解决方案


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

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

npm cache clean --force

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

默认值:~/.npmlinux上,或%AppData%/npm-cache在 Window 上

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

笔记:

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


推荐阅读