gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/.node
Posted ganiks
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/.node相关的知识,希望对你有一定的参考价值。
环境说明
[email protected]:/ganiks/parse-server$ npm -v 6.5.0 [email protected]:/ganiks/parse-server$ node -v v10.15.0
问题描述
安装部署 ParseServer服务
[email protected]:/ganiks/parse-server# npm install -g parse-server mongodb-runner
遇到了第一个异常
> [email protected] install /usr/local/lib/node_modules/bcrypt > node-pre-gyp install --fallback-to-build node-pre-gyp WARN Using needle for node-pre-gyp https download node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v64 ABI, glibc) (falling back to source compile with node-gyp) node-pre-gyp WARN Hit error EACCES: permission denied, mkdir ‘/usr/local/lib/node_modules/bcrypt/lib‘ gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/10.15.0" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/bcrypt/.node-gyp" gyp WARN install got an error, rolling back install
完整的Error信息:
> [email protected] install /usr/local/lib/node_modules/bcrypt > node-pre-gyp install --fallback-to-build node-pre-gyp WARN Using needle for node-pre-gyp https download node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v64 ABI, glibc) (falling back to source compile with node-gyp) node-pre-gyp WARN Hit error EACCES: permission denied, mkdir ‘/usr/local/lib/node_modules/bcrypt/lib‘ gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/10.15.0" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/bcrypt/.node-gyp" gyp WARN install got an error, rolling back install gyp WARN install got an error, rolling back install gyp ERR! configure error gyp ERR! stack Error: EACCES: permission denied, mkdir ‘/usr/local/lib/node_modules/bcrypt/.node-gyp‘ gyp ERR! System Linux 3.13.0-164-generic gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/usr/local/lib/node_modules/bcrypt/lib/binding" "--napi_version=3" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v64" gyp ERR! cwd /usr/local/lib/node_modules/bcrypt gyp ERR! node -v v10.15.0 gyp ERR! node-gyp -v v3.8.0 gyp ERR! not ok node-pre-gyp ERR! build error node-pre-gyp ERR! stack Error: Failed to execute ‘/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/usr/local/lib/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64‘ (1) node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/bcrypt/node_modules/node-pre-gyp/lib/util/compile.js:83:29) node-pre-gyp ERR! stack at ChildProcess.emit (events.js:182:13) node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:962:16) node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5) node-pre-gyp ERR! System Linux 3.13.0-164-generic node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/bcrypt/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build" node-pre-gyp ERR! cwd /usr/local/lib/node_modules/bcrypt node-pre-gyp ERR! node -v v10.15.0 node-pre-gyp ERR! node-pre-gyp -v v0.12.0 node-pre-gyp ERR! not ok Failed to execute ‘/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/usr/local/lib/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64‘ (1) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2019-01-17T08_54_06_070Z-debug.log
解决方案
npm install 添加参数 --unsafe-perm
[email protected]:/ganiks/parse-server# sudo npm install -g parse-server mongodb-runner --unsafe-perm
参考资料
https://github.com/nodejs/node-gyp/issues/454
https://github.com/nfarina/homebridge/issues/405#issuecomment-164803485
If npm detects it is running as root it drops to a non-privileged user which then doesn‘t have permissions to write to
/root/.node-gyp
.The --unsafe-perm option stops it from changing user.
nvm doesn‘t have this problem when not using sudo because it stores everything under the current users‘ home directory.
https://docs.npmjs.com/misc/config#unsafe-perm--unsafe-perm
看官方文档的解释
unsafe-perm
Default: false if running as root, true otherwise
Type: Boolean
Set to true to suppress the UID/GID switching when running package scripts.If set explicitly to false, then installing as a non-root user will fail.
以上是关于gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/.node的主要内容,如果未能解决你的问题,请参考以下文章
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/.node
npm install时报错gyp ERR! stack Error: Can't find Python executable "2.7"
npm i安装包依赖时 gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env(
npm i安装包依赖时 gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env