• npm安装报错:Error: EACCES: permission denied


    报错如下:

    sudo npm i webpack -g
    /Users/xesfe/.npm-global/bin/webpack -> /Users/xesfe/.npm-global/lib/node_modules/webpack/bin/webpack.js
    # System-wide .profile for sh(1)
    
    > fsevents@1.2.11 install /Users/xesfe/.npm-global/lib/node_modules/webpack/node_modules/fsevents
    > node-gyp rebuild
    
    gyp ERR! configure error
    gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/xesfe/.npm-global/lib/node_modules/webpack/node_modules/fsevents/build'
    gyp ERR! System Darwin 19.2.0
    gyp ERR! command "/Users/xesfe/.nvm/versions/node/v10.16.2/bin/node" "/Users/xesfe/.nvm/versions/node/v10.16.2/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
    gyp ERR! cwd /Users/xesfe/.npm-global/lib/node_modules/webpack/node_modules/fsevents
    gyp ERR! node -v v10.16.2
    gyp ERR! node-gyp -v v3.8.0
    gyp ERR! not ok
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/webpack/node_modules/fsevents):
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 install: `node-gyp rebuild`
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
    
    + webpack@4.41.4
    updated 1 package in 22.243s
    

    方案1:

     npm install --unsafe-perm=true --allow-root -g nodeppt
    

      在安装的时候一直报错nodeppt,通过查资料添加--unsafe-perm=true --allow-root,可以解决问题,git上issue:https://github.com/npm/npm/issues/17268,这方案貌似不是那么的优雅,因此寻找第二种方案。

    方案2

    1、建立全局文件夹配置

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

      ps:在mac下不要建以点(.)开头的配置文件,否则还是解决不了。

    2、修改环境变量

    vi /etc/profile 
    

      如果文件是只读的,改一下文件的读写权限

    sudo chmod 777 /etc/profile
    

     在/etc/profile追加

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

    3、激活环境变量配置

    source /etc/profile
    

    4、再次按装

    i webpack -g
    /Users/xesfe/npm-config/bin/webpack -> /Users/xesfe/npm-config/lib/node_modules/webpack/bin/webpack.js
    
    > fsevents@1.2.11 install /Users/xesfe/npm-config/lib/node_modules/webpack/node_modules/fsevents
    > node-gyp rebuild
    
      SOLINK_MODULE(target) Release/.node
      CXX(target) Release/obj.target/fse/fsevents.o
      SOLINK_MODULE(target) Release/fse.node
    + webpack@4.41.4
    

    5、如果你执行webpack 发现

    zsh: command not found: webpack
    

      那添加到环境变量就可以了。

    执行以下操作:

    vi .bash_profile  

     在.bash_profile添加

    export NPM_CONFIG=~/npm-config
    export PATH=$PATH:$NPM_CONFIG/bin
    

      执行以下命令,让环境变量生效。

    source .bash_profile
    

    OK,完美解决权限不够的问题。

    参考:  

    https://www.jianshu.com/p/7192b336c6cd

      

     

  • 相关阅读:
    企业应用的互联网化(2010年2月)
    Flex的危局,还是HTML5的盛宴?
    在MBP上自由切换显卡
    Django的中文编码问题
    Jenkins+Maven+SVN快速搭建持续集成环境(转)
    解决 phpmyadmin #2002 无法登录 MySQL 服务器
    Spring框架中获得DataSource对象的方法(转)
    jetty 源代码地址
    eclipse中js文件报missing semicolon
    等额本息贷款月付款额的推导公式
  • 原文地址:https://www.cnblogs.com/yiyi17/p/12080823.html
Copyright © 2020-2023  润新知