gpt4 book ai didi

javascript - NPM/错误 : EACCES: permission denied, 扫描目录

转载 作者:行者123 更新时间:2023-12-05 00:35:15 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Getting EACCESS when running NPM 8 as root

(1 个回答)


6 个月前关闭。




当我输入“npm run build:prod”时

build:prod
npm run build -- --configuration production --aot --optimization=false
我收到此错误:
> fancy-name@0.0.0 build:prod
> npm run build -- --configuration production --aot --optimization=false

glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
errno: -13,
code: 'EACCES',
syscall: 'scandir',
path: '/root/.npm/_logs'
}
npm WARN logfile Error: EACCES: permission denied, scandir '/root/.npm/_logs'
npm WARN logfile error cleaning log files [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
npm WARN logfile errno: -13,
npm WARN logfile code: 'EACCES',
npm WARN logfile syscall: 'scandir',
npm WARN logfile path: '/root/.npm/_logs'
npm WARN logfile }
⸨⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⸩ ⠙ : WARN logfile Error: EACCES: permission denied, scandir '/root/.npm/_logs'
> fancy-name@0.0.0 build
> ng build "--configuration" "production" "--aot" "--optimization=false"

Node.js version v17.4.0 detected.file Error: EACCES: permission denied, scandir '/root/.npm/_logs'
Odd numbered Node.js versions will not enter LTS status and should not be used for production. For more information, please see https://nodejs.org/en/about/releases/.
This version of CLI is only compatible with Angular versions ^13.0.0-next || >=13.0.0 <14.0.0,ogs'
but Angular version 12.1.3 was found instead.

Please visit the link below to find instructions on how to update Angular.
https://update.angular.io/
我已经尝试删除 node_module 和 package.json 并运行 NPM install再次,但它没有工作
(Linux 4.19.0-16-cloud-amd64)
编辑:用 chown -R root /path/of/your/project 解决

最佳答案

这是一个令人困惑的错误,这是可以理解的;你跑npm以root身份,但它说您无权访问这些文件?有一个很好的理由:) 这些问题本质上是关于同一件事的:

  • fs.readFileSync throwing EACCESS when called using `npm`, but not using `node`
  • Bower install EACCESS error

  • 我的 quite long answer详细介绍正在发生的事情,但本质是这样的:

    (NPM) ... uses this bit of code to determine who to run as:

    const { uid, gid } = isRoot ? inferOwner.sync(cwd) : {}

    and as the docs of infer-owner module says:Infer the owner of a path based on the owner of its nearest existing parent


    因此,如果您以 root 身份运行 NPM,您还需要将当前目录的所有者更改为 root:
    chown -R root /path/of/your/project
    但是所有这些麻烦都应该指向真正的解决方案:不要以 root 身份运行 NPM。你不知道什么样的脚本可以作为 postinstall 运行。触发器或类似的。注意安全;仅在必要时使用 root 帐户,使用 sudo .
    附录:尝试 Node 14
    如链接答案中所述:

    This behavior is only for NPM versions >= 7. NPM versions < 7, which are the ones shipped with Node 12-14 work perfectly fine when running as root. So the quickest fix might simply be to use Node 14.


  • npm install -g nvm
  • nvm use 14
  • 关于javascript - NPM/错误 : EACCES: permission denied, 扫描目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70952903/

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