在 Azure 应用程序/ Web 服务上执行 "npm install" 出错:EPERM:操作不允许,lchown。

3
在配置了Node 12 LTS的Linux Azure App / Web Service上,将代码资源上传到/home/site/wwwroot/,其中包括一个package.json文件。我以root身份运行npm install时会出现下面进一步展示的异常。
同样的异常会在两个不同的Azure App / Web Services上发生,一个用于UI,另一个用于API(因此是两个不同的代码集)。但错误模式是相同的:
它无法更改位于/home/site/wwwroot/node_modules/[...] /build-optimizer/node_modules/.bin/下的目录的所有权,但仅因为.../.bin/子目录本身从未被创建。
再次说明,我在两种情况下都以root身份运行npm install。
有什么想法吗?请参见下文,谢谢。
24380 warn optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
24381 warn notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
24382 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS:    darwin
24382 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch:  any
24382 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS:   linux
24382 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64
24383 warn optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.1 (node_modules/karma/node_modules/fsevents):
24384 warn notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
24385 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS:    darwin
24385 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch:  any
24385 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS:   linux
24385 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64
24386 verbose stack Error: EPERM: operation not permitted, lchown '/home/site/wwwroot/node_modules/@angular-devkit/build-optimizer/node_modules/.bin/tsserver'
24387 verbose cwd /home/site/wwwroot
24388 verbose Linux 4.15.0-112-generic
24389 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
24390 verbose node v12.19.0
24391 verbose npm  v6.14.8
24392 error code EPERM
24393 error syscall lchown
24394 error path /home/site/wwwroot/node_modules/@angular-devkit/build-optimizer/node_modules/.bin/tsserver
24395 error errno -1
24396 error Error: EPERM: operation not permitted, lchown '/home/site/wwwroot/node_modules/@angular-devkit/build-optimizer/node_modules/.bin/tsserver'
24396 error  [OperationalError: EPERM: operation not permitted, lchown '/home/site/wwwroot/node_modules/@angular-devkit/build-optimizer/node_modules/.bin/tsserver'] {
24396 error   cause: [Error: EPERM: operation not permitted, lchown '/home/site/wwwroot/node_modules/@angular-devkit/build-optimizer/node_modules/.bin/tsserver'] {
24396 error     errno: -1,
24396 error     code: 'EPERM',
24396 error     syscall: 'lchown',
24396 error     path: '/home/site/wwwroot/node_modules/@angular-devkit/build-optimizer/node_modules/.bin/tsserver'
24396 error   },
24396 error   errno: -1,
24396 error   code: 'EPERM',
24396 error   syscall: 'lchown',
24396 error   path: '/home/site/wwwroot/node_modules/@angular-devkit/build-optimizer/node_modules/.bin/tsserver',
24396 error   parent: '@angular-devkit/build-optimizer'
24396 error }
24397 error The operation was rejected by your operating system.
24397 error It is likely you do not have the permissions to access this file as the current user
24397 error
24397 error If you believe this might be a permissions issue, please double-check the
24397 error permissions of the file and its containing directories, or try running
24397 error the command again as root/Administrator.
24398 verbose exit [ -1, true ]



上传代码资产到/home/site/wwwroot/后,你为什么要这样做? - Jason Pan
如果可以的话,你能展示一下wwwroot目录下的文件夹截图吗? - Jason Pan
1
通常情况下,只要本地能够成功运行,使用本地 git 或 git push 修改代码,就会在 git action 中重新构建和发布,无需在 kudu 中手动执行 npm install 命令。 - Jason Pan
@JasonPan 谢谢你。你说的完全正确。这个问题正在单独调查,因为它应该已经自动触发了。即便如此,上述操作也应该成功。 - NYCeyes
4
我自己遇到了这个问题,我运行了npm cache clean --force,然后它又可以正常工作了。也许这能帮助别人。 - semkeijsper
1个回答

4

我遇到了完全相同的问题。感谢semkeijsper的评论,解决方法是:在package.json中:

npm install

被修改为:

"npm cache clean --force && npm install"

1
对我来说有效,但每次我都会得到不同二进制文件的错误。只需一直运行该命令,直到成功为止。 - Birla

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接