npm install 報錯,提示gyp ERR! stack Error: EACCES: permission denied
,下面是具體情況
> [email protected] install /www/server/yapi/vendors/node_modules/dtrace-provider
> node-gyp rebuild || node suppress-error.js
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/10.15.3"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/www/server/yapi/vendors/node_modules/dtrace-provider/.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 '/www/server/yapi/vendors/node_modules/dtrace-provider/.node-gyp'
gyp ERR! System Linux 3.10.0-514.26.2.el7.x86_64
gyp ERR! command "/usr/local/src/node-v10.15.3-linux-x64/bin/node" "/usr/local/src/node-v10.15.3-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /www/server/yapi/vendors/node_modules/dtrace-provider
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
> [email protected] postinstall /www/server/yapi/vendors/node_modules/core-js
> node scripts/postinstall || echo "ignore"
Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock
Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
> [email protected] postinstall /www/server/yapi/vendors/node_modules/jsonpath
> node lib/aesprim.js > generated/aesprim-browser.js
sh: generated/aesprim-browser.js: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node lib/aesprim.js > generated/aesprim-browser.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall 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-06-05T15_08_06_583Z-debug.log
猜測可能是因爲沒有權限讀寫,ls -la
看下文件權限設置情況
[root@root vendors]# ls -la
drwxr-xr-x 307 root root 12288 Jun 5 23:08 node_modules
-rwxr-xr-x 1 root root 5880 Jun 5 23:06 package.json
-rw-r--r-- 1 root root 900847 Jun 5 23:06 package-lock.json
只有root用戶組有讀寫權限,其他只讀,將node_modules
文件夾修改權限,再執行看看
[root@root vendors]# npm i --production
> [email protected] postinstall /www/server/yapi/vendors/node_modules/jsonpath
> node lib/aesprim.js > generated/aesprim-browser.js
sh: generated/aesprim-browser.js: Permission denied
npm WARN [email protected] requires a peer of mongoose@^4.1.12 but none is installed. You must install peer dependencies yourself.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node lib/aesprim.js > generated/aesprim-browser.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall 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-06-05T15_10_22_303Z-debug.log
經過面向搜索引擎開發,有提到用sudo,但是發現還是不行,實際原因是由於用的是root
賬戶權限執行npm
,而npm
默認是不適用root權限創建內容,因此會出現權限問題而導致失敗,加上參數--unsafe-perm=true --allow-root
即可解決問題。
npm install --production --unsafe-perm=true --allow-root