在 CentOS 7 下使用 npm install 安装时出现错误,删除 node_modules 和 package-lock.json 重新安装都无法解决,错误信息如下:

gyp ERR! stack Error: EACCES: permission denied, mkdir '/opt/nideshop-admin/node_modules/node-sass/.node-gyp'
gyp ERR! System Linux 3.10.0-957.21.3.el7.x86_64
gyp ERR! command "/usr/local/src/node-v12.18.3-linux-x64/bin/node" "/opt/nideshop-admin/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /opt/nideshop-admin/node_modules/node-sass
gyp ERR! node -v v12.18.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1

解决方法:

npm install -unsafe-perm

标签: Node.js, CentOS