报错如下:

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

  

 

npm安装报错:Error: EACCES: permission denied的更多相关文章

  1. npm安装node-sass失败,EACCES: permission denied

    增加--unsafe-perm,即 sudo npm install node-sass --unsafe-perm --save-dev 成功安装node-sass

  2. npm install 报错,提示`gyp ERR! stack Error: EACCES: permission denied` 解决方法

    m install 报错,提示gyp ERR! stack Error: EACCES: permission denied 猜测可能是因为没有权限读写,ls -la看下文件权限设置情况 [root@ ...

  3. mac上安装webpack报错解决方法Hit error EACCES: permission denied, mkdir '/usr/local/lib/node_modules/webpack

    node-pre-gyp WARN Using needle for node-pre-gyp https download node-pre-gyp WARN Pre-built binaries ...

  4. npm install Error: EACCES: permission denied, mkdir

    今天研究Electron的时候,全局安装运行 npm install electron -g时侯,报下面的错误: Error: EACCES: permission denied, mkdir '/U ...

  5. fastadmin安装定时插件报错 ZipArchive::extractTo(): Permission denied

    环境linux上直接安装  如果你是在win开发号直接部署的应该是没问题  我是直接在linux安装的 这几天研了下fastadmin 想用他的定时可是在使用的时候报错   ZipArchive::e ...

  6. Error: EACCES: permission denied, mkdir '......node-sass/build'错误解决方案

    安装node-sass时出现一下错误: gyp ERR! configure error gyp ERR! stack Error: EACCES: permission denied, mkdir ...

  7. Error: EACCES: permission denied, symlink

    环境说明 ganiks@ganiks-ubuntu-trusty-64:/ganiks/parse-server$ npm -v 6.5.0 ganiks@ganiks-ubuntu-trusty-6 ...

  8. npm install 时出现的 EACCES: permission denied 错误的可能有效的解决方案

    最近我开始接触手机 app 的编写,公司用到了 Nativescript.当我下载了公司的项目后,在配置时出现了不少的问题,其中出现概率最高的就是 EACCES: permission denied ...

  9. npm install 报错 error Unexpected end of JSON input while parsing near '...sShrinkwrap":false,"d' 解决办法

    npm install 报错 : error Unexpected end of JSON input while parsing near '...sShrinkwrap":false,& ...

随机推荐

  1. 攻防世界--maze

    测试文件下载:https://adworld.xctf.org.cn/media/task/attachments/fa4c78d25eea4081864918803996e615 1.准备 获得信息 ...

  2. 【学习总结】Python-3-字符串运算符与字符串格式化

    参考: 本教程的评论区:菜鸟教程-Python3-Python数字 字符串运算符: 实例变量a值为字符串 "Hello",b变量值为 "Python": 字符串 ...

  3. http响应代码解释

    200:成功响应 302:找到,但是请求的资源在另外一个不同的url中. 400:错误请求.这个请求不能被服务器所理解,客户端必须修改请求. 401:未认证,这个请求需要用户认证. 404:未找到.服 ...

  4. 如何为nginx配置https(免费证书)

    前言: 给http协议申请ssl免费证书,还是比较主流的一种方式,但是逐渐得一些浏览器不支持自签名的证书了.毕竟这是为了使用者及平台都变得安全的方式,所以无可厚非的,而且也有很多网站即使不使用商业付费 ...

  5. AR/VR增强现实 虚拟现实,嵌入式解决方案探讨

    AR/VR增强现实 虚拟现实,嵌入式解决方案探讨 北京太速科技有限公司 视频增强现实产品与视频矩阵拼接等产品开发,增强现实技术包含了多媒体.三维建模.实时视频显示及控制.多传感器融合.实时跟踪及注册. ...

  6. 抽象类(abstract)与接口(interface)的区别

    如果一个类中包含抽象方法,那么这个类就是抽象类.abstract只能用来修饰类或者方法,不能用来修饰属性. 接口是指一个方法的集合,接口中的所有方法都没有方法体.接口通过关键字interface实现. ...

  7. java类使用

    package java04; /* * 通常情况下,一个类不能直接使用,需要创建一个对象,才能使用 * *步骤: * 1.导包:就是指出需要使用的类在什么位置 * import 包名称.类名称: * ...

  8. JVM内存组成

    JVM的内存区域模型 1.方法区 也称永久代.非堆. 用于存储虚拟机加载的类信息.常量.静态变量,是各个线程共享的内存区域. 默认最小值为16MB,最大值为64MB,可以通过-XX:PermSize和 ...

  9. 前端每日实战:49# 视频演示如何用纯 CSS 创作一支诱人的冰棍

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/vrxzMw 可交互视频教程 此视频 ...

  10. spark大数据快速分析第二章

    1.驱动程序通过一个SparkContext对象来访问Spark,此对象代表对计算集群的一个连接.shell已经自动创建了一个SparkContext对象.利用SparkContext对象来创建一个R ...