gpt4 book ai didi

node.js - npm 错误代码 EACCES 243. 是什么导致 npm 缓存中的某些目录在没有设置执行标志的情况下被创建?

转载 作者:行者123 更新时间:2023-12-04 19:31:33 28 4
gpt4 key购买 nike

在我们的 TeamCity 代理(centos 7)上运行构建时,使用 teamcity 用户运行的任何 npm 命令(版本 7.24.2)都会生成以下错误:

[Step 2/25] npm cache clear --force
[npm cache clear --force] npm WARN using --force Recommended protections disabled.
[npm cache clear --force] npm ERR! code EACCES
[npm cache clear --force] npm ERR! syscall unlink
[npm cache clear --force] npm ERR! path /data/teamcity-agent/npm-cache/_cacache/index-v5/34/70188cc2e95f746adf32e21191fb2cad2a56f8c7c78dcf4a0d1587143321
[npm cache clear --force] npm ERR! errno -13
[npm cache clear --force] npm ERR!
[npm cache clear --force] npm ERR! Your cache folder contains root-owned files, due to a bug in
[npm cache clear --force] npm ERR! previous versions of npm which has since been addressed.
[npm cache clear --force] npm ERR!
[npm cache clear --force] npm ERR! To permanently fix this problem, please run:
[npm cache clear --force] npm ERR! sudo chown -R 2158:993 "/data/teamcity-agent/npm-cache"
[npm cache clear --force]
[npm cache clear --force] npm ERR! A complete log of this run can be found in:
[npm cache clear --force] npm ERR! /data/teamcity-agent/npm-cache/_logs/2022-05-03T10_51_17_066Z-debug.log
[Step 2/25] Process exited with code 243
[Step 2/25] Process exited with code 243
[Step 2/25] Step npm cache clear (Node.js NPM) failed
但是当深入研究错误时,用户 teamcity 并不拥有 npm 缓存中的所有文件,它确实拥有,所有文件都归正确的用户所有。这是某些目录没有设置执行位。例如:
> cd /data/teamcity-agent/npm-cache
> ls -alR | grep drw-
drw-------. 2 teamcity teamcity 138 Apr 29 01:52 34
drw-------. 2 teamcity teamcity 138 Apr 29 09:54 cc
您可以在缓存中的数百个其他目录中看到两个只设置了所有者的读写位,所有其他的看起来像这样:
> cd /data/teamcity-agent/npm-cache/_cacache/content-v2/sha512
> ls -al
drwxr-xr-x. 257 teamcity teamcity 8192 Apr 28 12:10 .
drwxr-xr-x. 4 teamcity teamcity 32 Apr 28 12:10 ..
drwxr-xr-x. 7 teamcity teamcity 56 Apr 29 01:52 00
drwxr-xr-x. 11 teamcity teamcity 96 Apr 28 12:10 01
.....
如果没有在目录上设置所有者执行标志,则 teamcity 代理无法修改目录的内容,因此所有 npm 命令都会失败。该问题的快速解决方法是运行:
> chmod -R +755 /data/teamcity-agent/npm-cache
但随着时间的推移,问题又出现在 npm 缓存的不同区域。这导致了这里的实际问题:
是什么导致 npm 缓存中的某些目录在没有设置执行标志的情况下被创建?
我检查了代理上只安装了一个版本的 npm。顺便提一下,TeamCity 代理是在 centos 7 上运行的(CentOS Linux release 7.9.2009 (Core))

最佳答案

我们从未深入了解导致此问题的原因,但我们已经实现了一个修复程序来阻止它发生。
最后,我们通过/usr/etc/npmrc 中的文件将 npm 缓存从/data/teamcity-agent/npm-cache 移动到/tmp/teamcity-agent/npm-cache,该文件现在设置为以下内容:

$ cat /usr/etc/npmrc
registry=https://npm-private-registry.aaa.bbb/
always-auth=true
_auth="................"
email=aaa@bbb.ccc
cache=/tmp/teamcity-agent/npm-cache
当您列出 npm 配置时,如下所示:
$ npm config list
; "global" config from /usr/etc/npmrc

_auth = (protected)
always-auth = true
cache = "/tmp/teamcity-agent/npm-cache"
; email = "aaa@bbb.ccc" ; overridden by user
registry = "https://npm-private-registry.aaa.bbb/"

; "user" config from /home/centos/.npmrc
...
...
这两个位置之间的唯一区别是/data/teamcity-agent 归 teamcity 用户所有,而/tmp/teamcity-agent 归 root 用户所有。

关于node.js - npm 错误代码 EACCES 243. 是什么导致 npm 缓存中的某些目录在没有设置执行标志的情况下被创建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72104367/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com