今天遇到个情况,因需要在无网络环境中部署Jenkins服务,于是在随便找一台服务器配置Jenkins任务,以便拷贝其node_moudles目录,在执行npm install的时候,提示了这个错误:gyp ERR! stack Error: EACCES: permission denied, mkdir '/data/jenkins_home/workspace/xxxx/node_modules/node-sass/.node-gyp'

原因

具体错误日志:

1
2
3
4
5
6
7
8
9
gyp verb remove removing development files for version: 14.17.0
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/data/jenkins_home/workspace/xxxx/node_modules/node-sass/.node-gyp'
gyp ERR! System Linux 3.10.0-693.2.2.el7.x86_64
gyp ERR! command "/usr/local/nodejs/node-v14.17.0-linux-x64/bin/node" "/data/jenkins_home/workspace/xxxx/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /data/jenkins_home/workspace/车站档案-前端/node_modules/node-sass
gyp ERR! node -v v14.17.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

由于是在root用户执行的npm install,所以应该不存在权限的问题,应该是和某些服务一样,通常不建议使用root启动活这些某些操作,于是度之,需要加上点参数进去,以便能让root用户执行。

解决方案

1
npm install --unsafe-perm=true --allow-root