mac 系统node.js降级及修改node.js版本失败解决办法

mac 系统node.js降级及修改node.js版本失败解决办法

在搭建react工程的过程中,使用npm install安装命令,遇到如下报错。
原来目前 fsevents 还没支持用 node v11+ 版本,解决方案就是降低 node 的版本再安装 fsevents。
据说是node版本太高的原因,所以采用降低node版本的办法。
具体操作过程如下:
node-pre-gyp ERR! Pre-built binaries not found for fsevents@1.0.14 and node@14.7.0 (node-v83 ABI) (falling back to source compile with node-gyp)

1. 查看当前版本

$ node -v 
v14.7.0

2. 查看当前有哪些可以安装的版本

$ brew search node
==> Formulae
libbitcoin-node       node ✔                node-sass             node@12               nodebrew              nodenv
llnode                node-build            node@10               node_exporter         nodeenv

3.安装node 10 ;

$ brew install node@10
==> Downloading https://mirrors.aliyun.com/homebrew/homebrew-bottles/bottles/node%4010-10.21.0.catalina.bottle.tar.gz
######################################################################## 100.0%
==> Pouring node@10-10.21.0.catalina.bottle.tar.gz
==> Caveats
node@10 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have node@10 first in your PATH run:
  echo 'export PATH="/usr/local/opt/node@10/bin:$PATH"' >> /Users/kelin/.bash_profile

For compilers to find node@10 you may need to set:
  export LDFLAGS="-L/usr/local/opt/node@10/lib"
  export CPPFLAGS="-I/usr/local/opt/node@10/include"

==> Summary
🍺  /usr/local/Cellar/node@10/10.21.0: 4,302 files, 54.0MB

4. 解除高版本的关联关系

$ brew unlink node
Unlinking /usr/local/Cellar/node/14.4.0... 4 symlinks removed

5.关联node10版本

$ forum-front kelin$ brew link node@10
Warning: node@10 is keg-only and must be linked with --force

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/node@10/bin:$PATH"' >> /Users/kelin/.bash_profile
以上提示“node@10 is keg-only and must be linked with --force”
需要强制关联node10版本

6. 执行强制关联低版本命令 :brew link --force --overwrite node@10

$ brew link --force --overwrite node@10
Linking /usr/local/Cellar/node@10/10.21.0...
Error: Could not symlink lib/node_modules/npm/.licensee.json
/usr/local/lib/node_modules/npm is not writable.
以上提示:/usr/local/lib/node_modules/npm is not writable.
npm文件夹不可写,没有写权限,下一步设置权限

7. 一步到位设置node_models权限;

 $ cd /usr/local/lib/node_modules/
 $ sudo chmod -R 777 node_modules
 $Password:(输入电脑密码)

8.再次执行强制关联低版本命令 :brew link --force --overwrite node@10

$ brew link --force --overwrite node@10
Linking /usr/local/Cellar/node@10/10.21.0... 3823 symlinks created

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/node@10/bin:$PATH"' >> /Users/kelin/.bash_profile

9. 将配置写到配置文件;

 $ echo 'export PATH="/usr/local/opt/node@10/bin:$PATH"' >> /Users/kelin/.bash_profile 

10.查看修改后的版本

$ node -v
v10.21.0
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值