ubuntu下nodejs报错:let notifier = require('update-notifier')({pkg})

本文提供了一套详细的步骤来解决在Ubuntu系统上遇到的Node.js安装错误,包括移除错误的node_modules,卸载并重新安装Node.js,以及配置npm镜像源,最后通过n管理器安装最新稳定版的Node.js。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误:

/usr/local/lib/node_modules/npm/bin/npm-cli.js:85
      let notifier = require('update-notifier')({pkg})
      ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3

解决办法:

1.移除错误的node_modules

cd /usr/local/lib/
rm node_modules/ -rf

2.卸载nodejs:

sudo apt-get autoremove nodejs

3.更新源,准备重新安装:

sudo apt-get update
sudo apt-get install -y python-software-properties software-properties-common
sudo add-apt-repository ppa:chris-lea/node.j
sudo apt-get update

4.安装nodejs:

sudo apt-get install nodejs
sudo apt install nodejs-legacy
sudo apt install npm

5.更新npm的包镜像源,方便快速下载

sudo npm config set registry https://registry.npm.taobao.org
sudo npm config list

6.全局安装n管理器(用于管理nodejs版本)

sudo npm install n -g

7.安装最新的nodejs(stable版本)

sudo n stable
sudo node -v
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值