node.js - 全局 NPM 包安装的简单 CircleCI 2.0 配置失败
问题描述
我有一个运行良好的 Dockerfile:
FROM node:10
RUN npm set unsafe-perm true
RUN npm install -g '@oresoftware/r2g@0.0.132'
但与上述 Dockerfile 相同的 CircleCI config.yml 文件不起作用:
{
"version": 2,
"jobs": {
"build": {
"docker": [
{
"image": "circleci/node:10"
}
],
"steps": [
{
"run": "npm set unsafe-perm true"
},
{
"run": "npm install -g --loglevel=warn '@oresoftware/r2g@0.0.132'"
}
]
}
}
}
我使用上面的 config.yml 文件在 CircleCI 上收到以下错误:
#!/bin/bash -eo pipefail
npm install -g --loglevel=warn @oresoftware/r2g
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /home/circleci/.npm/_logs/2018-06-18T18_26_53_651Z-debug.log
Exited with code 243
CircleCI 2.0 应该使用 Docker,所以我不确定为什么会发生此权限错误。
解决方案
tldr - 使用以下前缀:
npm install --prefix=$HOME/.local --global serverless
- 替换
serverless
为您自己的全局包要求。
背景:
- 经过一些实验,上面似乎是我发现的最干净的方法。
CircleCI 的当前
circleci/node:lts-buster
图像在路径上有以下内容:/home/circleci/.local/bin:/home/circleci/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/home/circleci/bin
由于写入权限被阻止,我无法写入。- 我能够写信给
/home/circleci/.local/bin
- 将
--prefix=$HOME/.local
选项添加到npm install
命令意味着然后将全局包安装到/home/circleci/.local/bin
- 安装后,就我而言,该命令
serverless
是可执行的。
推荐阅读
- node.js - 无法通过 heroku 连接到 MongoDB,但可以在 localhost 上运行
- python - 跨模块的 Python 全局变量
- python - 使用 Pytorch Lightning 时如何将指标(例如验证损失)记录到 TensorBoard?
- java - 如何从侦听器返回 ArrayList
- tensorflow - 强大的 IDE,可减少 yolo/darkflow 中训练数据集的时间
- php - ReactPHP:使用启动/停止命令运行服务器
- javascript - 条纹重定向到结账
- r - 强制 r 在变异后不舍入结果
- python - 为什么我的 pygame rect 敌人在被杀死后会减速?
- javascript - 在 Vue 3 中访问和修改 slot 的元素