【问题标题】:NPM cache issueNPM 缓存问题
【发布时间】:2022-11-05 18:48:03
【问题描述】:

我正在使用 jenkins 执行基于 cypress 的测试用例。我正在使用 cypress 在 github repo https://github.com/cypress-io/cypress-example-kitchensink/blob/master/Jenkinsfile 中提供的厨房水槽示例 但是当我在詹金斯工作中执行这个时,我得到了错误

npm ci

npm WARN prepare removing existing node_modules/ before installation
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /.npm
npm ERR! errno -13
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 501:20 "/.npm"
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /.npm
npm ERR! errno -13
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 501:20 "/.npm"
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /.npm
npm ERR! errno -13
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 501:20 "/.npm"
npm ERR! code EACCES

如需额外信息: Jenkins 安装在我的 MAC 操作系统中并在端口 8080(默认端口)中运行,节点 js 也安装在我的本地系统中,版本为 17.5.0

但是 dockerfile 在上述 repo 示例中使用 docker 中的 cypress 映像并在容器中安装相关依赖项

【问题讨论】:

    标签: node.js docker jenkins npm cypress


    【解决方案1】:

    在运行 npm ci 之前,请尝试以下任一命令:

    sudo npm cache clean --force //forcefully remove any npm folder before install
    OR
    sudo chown -R 501:20 "/.npm" //suggested by jenkins
    

    【讨论】:

    【解决方案2】:

    这不能通过不同答案中制定的任何方式来解决。我发现的唯一解决方案就是通过更改 npm 版本来避免它。 npm 的当前版本是9.0.1,而最新版本是8.92.2。遵循以下命令:

    sudo npm i -g npm@9.0.1 && sudo npm i -g npx --force && sudo npx create-react-app app-name
    

    我希望它会起作用,就像我的情况一样。

    【讨论】:

      猜你喜欢
      • 2017-12-15
      • 2011-08-12
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 2020-11-04
      • 2011-10-30
      • 2011-04-07
      相关资源
      最近更新 更多