0914-npm EACCES: permission denied权限问题官网终极解决办法

版权声明:本文为博主原创文章,转载请注明地址。技术交流群 QQ:206831226,备注CSDN。 https://blog.csdn.net/yanxilou/article/details/88965177

node saas 模块安装失败,无法打包成功,异常堆栈如下:

[root@dev ems-web]# npm rebuild node-sass

> [email protected] install /root/.jenkins/workspace/ems-web/node_modules/node-sass
> node scripts/install.js

Unable to save binary /root/.jenkins/workspace/ems-web/node_modules/node-sass/vendor/linux-x64-64 : { Error: EACCES: permission denied, mkdir '/root/.jenkins/workspace/ems-web/node_modules/node-sass/vendor'
    at Object.mkdirSync (fs.js:753:3)
    at sync (/root/.jenkins/workspace/ems-web/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/root/.jenkins/workspace/ems-web/node_modules/mkdirp/index.js:77:24)
    at checkAndDownloadBinary (/root/.jenkins/workspace/ems-web/node_modules/node-sass/scripts/install.js:114:11)
    at Object.<anonymous> (/root/.jenkins/workspace/ems-web/node_modules/node-sass/scripts/install.js:157:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
  errno: -13,
  syscall: 'mkdir',
  code: 'EACCES',
  path:
   '/root/.jenkins/workspace/ems-web/node_modules/node-sass/vendor' }

> [email protected] postinstall /root/.jenkins/workspace/ems-web/node_modules/node-sass
> node scripts/build.js

Building: /usr/local/nodejs/bin/node /root/.jenkins/workspace/ems-web/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [ '/usr/local/nodejs/bin/node',
gyp verb cli   '/root/.jenkins/workspace/ems-web/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library=' ]
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` succeeded python2 /usr/bin/python2
gyp verb check python version `/usr/bin/python2 -c "import sys; print "2.7.5
gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
gyp verb get node dir no --target version specified, falling back to host node version: 10.15.1
gyp verb command install [ '10.15.1' ]
gyp verb install input version string "10.15.1"
gyp verb install installing version: 10.15.1
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 10.15.1
gyp verb ensuring nodedir is created /root/.node-gyp/10.15.1
gyp WARN EACCES user "admin" does not have permission to access the dev dir "/root/.node-gyp/10.15.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/root/.jenkins/workspace/ems-web/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '--node_gyp_internal_noretry', '10.15.1' ]
gyp verb install input version string "10.15.1"
gyp verb install installing version: 10.15.1
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 10.15.1
gyp verb ensuring nodedir is created /root/.jenkins/workspace/ems-web/node_modules/node-sass/.node-gyp/10.15.1
gyp WARN install got an error, rolling back install
gyp verb command remove [ '10.15.1' ]
gyp verb remove using node-gyp dir: /root/.jenkins/workspace/ems-web/node_modules/node-sass/.node-gyp
gyp verb remove removing target version: 10.15.1
gyp verb remove removing development files for version: 10.15.1
gyp WARN install got an error, rolling back install
gyp verb command remove [ '10.15.1' ]
gyp verb remove using node-gyp dir: /root/.jenkins/workspace/ems-web/node_modules/node-sass/.node-gyp
gyp verb remove removing target version: 10.15.1
gyp verb remove removing development files for version: 10.15.1
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/root/.jenkins/workspace/ems-web/node_modules/node-sass/.node-gyp'
gyp ERR! System Linux 3.10.0-693.el7.x86_64
gyp ERR! command "/usr/local/nodejs/bin/node" "/root/.jenkins/workspace/ems-web/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /root/.jenkins/workspace/ems-web/node_modules/node-sass
gyp ERR! node -v v10.15.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node scripts/build.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-04-02T02_24_00_916Z-debug.log

解决方案:

1.建立全局文件夹配置

mkdir ~/.npm-global

npm config set prefix '~/.npm-global'

 2.修改环境变量

vi /etc/profile 

 文件最后追加: 

# nodejs 配置
export PATH=~/.npm-global/bin:$PATH

 激活环境变量配置

 source /etc/profile

3.运行打包

npm install
[root@dev eweb]# npm install

> [email protected] install /root/.jenkins/workspace/eweb/node_modules/chromedriver
> node install.js

Current existing ChromeDriver binary is unavailable, proceding with download and extraction.
Downloading from file:  https://chromedriver.storage.googleapis.com/2.46/chromedriver_linux64.zip
Saving to file: /root/.jenkins/workspace/ems-web/node_modules/chromedriver/2.46/chromedriver/chromedriver_linux64.zip
Received 781K...
Received 1568K...
Received 2352K...
Received 3136K...
Received 3920K...
Received 4704K...
Received 5277K total.
Extracting zip contents
Copying to target path /root/.jenkins/workspace/ems-web/node_modules/chromedriver/lib/chromedriver
Fixing file permissions
Done. ChromeDriver binary available at /root/.jenkins/workspace/ems-web/node_modules/chromedriver/lib/chromedriver/chromedriver

> [email protected] install /root/.jenkins/workspace/ems-web/node_modules/node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.11.0/linux-x64-64_binding.node
Download complete  ] - :
Binary saved to /root/.jenkins/workspace/ems-web/node_modules/node-sass/vendor/linux-x64-64/binding.node
Caching binary to /root/.npm/node-sass/4.11.0/linux-x64-64_binding.node

> [email protected] postinstall /root/.jenkins/workspace/ems-web/node_modules/node-sass
> node scripts/build.js

Binary found at /root/.jenkins/workspace/ems-web/node_modules/node-sass/vendor/linux-x64-64/binding.node
Testing binary
Binary is fine
npm WARN [email protected] requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 13 packages from 11 contributors, removed 24 packages, updated 1 package and audited 31484 packages in 54.698s
found 81 vulnerabilities (66 low, 9 moderate, 5 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details
[root@dev ems-web]# ll
total 632
drwxr-xr-x    2 root root    188 Apr  1 12:15 build
drwxr-xr-x    2 root root     78 Apr  1 12:15 config
drwxr-xr-x    3 root root     38 Apr  1 22:15 dist
-rw-r--r--    1 root root   1127 Apr  1 12:15 index.html
drwxr-xr-x 1111 root root  32768 Apr  1 22:32 node_modules
-rw-r--r--    1 root root   3074 Apr  1 12:15 package.json
-rw-r--r--    1 root root 573930 Apr  1 22:32 package-lock.json
-rw-r--r--    1 root root   2947 Apr  1 12:15 README.md
drwxr-xr-x    8 root root    121 Apr  1 12:15 src
drwxr-xr-x    6 root root     69 Apr  1 12:15 static
[root@dev ems-web]# cd dist/
[root@dev dist]# ll
total 4
-rw-r--r-- 1 root root 1242 Apr  1 22:15 index.html
drwxr-xr-x 8 root root   77 Apr  1 22:15 static
[root@dev dist]# cd static/
[root@dev static]# ll
total 4
drwxr-xr-x 2 root root  141 Apr  1 22:15 css
drwxr-xr-x 2 root root   39 Apr  1 22:15 fonts
drwxr-xr-x 5 root root   47 Apr  1 22:15 images
drwxr-xr-x 2 root root   39 Apr  1 22:15 img
drwxr-xr-x 2 root root 4096 Apr  1 22:15 js
drwxr-xr-x 2 root root   45 Apr  1 22:15 json

猜你喜欢

转载自blog.csdn.net/yanxilou/article/details/88965177
今日推荐