Mac安装webpack步骤,失败npm ERR! Error: EACCES: permission denied, access,亲测有效

安装webpack步骤

  1. Mac在终端先获取root权限
    在mac下依赖包要写入系统重要文件夹里,由于没有先获取root权限所以写入失败,导致安装失败。失败显示:
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/gaorongrong/.npm/_logs/2021-08-08T08_34_15_754Z-debug.log
$ sudo -s

回车,输入密码即可

  1. 直接下载webpack会很慢,建议先下载国内镜像
npm install -g cnpm --registry=http://registry.npm.taobao.org
  1. 用cnpm下载webpack(全局安装webpack,如果之前安装过webpack或安装失败,先卸载:cnpm uninstall webpack -g)
cnpm install webpack@3.6.0 -g

(指定版本号3.6.0,因为vue cli2依赖该版本)

4.查看安装成功的版本号

webpack --version
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值