我正在尝试在 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 天。提前致谢
答案 0 :(得分:0)
Node js 应用程序的 Azure 部署失败:npm ERR!代码 EPERM
您可以尝试通过命令行清理 npm 缓存:
npm cache clean --force
如果它不适合您,请手动删除缓存文件。为此,请转到默认的 NPM 缓存文件夹并删除其内容:
默认:linux 上的 ~/.npm
,或 Window 上的 %AppData%/npm-cache
然后您可以尝试安装并启动您的应用程序。
注意:
避免使用 sudo npm install -g
,因为您可能会弄乱 npm 权限。而是将权限更改为 npm 的默认目录,或者将 npm 的默认目录更改为另一个目录。详情请见:https://docs.npmjs.com/getting-started/fixing-npm-permissions
答案 1 :(得分:0)
我可以通过两种方式解决这个问题。
在 Pipeline 中构建之后,安装 NPM 以包含 node_modules 文件夹并进行部署。 app service start 命令中的 npm start 运行应用程序。
Follow this link 使用 Doris 建议的链接,一切正常。