原node版本:v3.3.1
原npm版本:v2.3.0
希望npm升级到3.0以上
于是直接执行了命令:npm install -g npm
结果就报错了:
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside stric
升级之后npm命令用不了,输入npm -v,就直接下面异常:
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:413:25)
at Object.Module._extensions..js (module.js:448:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:471:10)
at startup (node.js:117:18)
at node.js:951:3
nvm is not compatible with the npm config “prefix” option: currently set to “”
Run npm config delete prefix
or nvm use --delete-prefix iojs-v3.3.1 --silent
to unset it.
方法一:
分析可能是node版本和nmp版本不兼容导致的,所幸之前安装了n模块,也是node包管理工具,就用n升级了node版本
n模块常用命令
(1) 安装node最新版本
n latest
(2) 安装稳定版
n stable
(3)查看可升级的版本
n ls
(4) 安装指定版本
n v7.10.0
(5) 查看已安装版本
n
(6) 删除指定版本
n rm 6.4.0
安装完成之后,用node –v查看,如果还是老版本,可能存在的原因:
n 切换之后的 node 默认装在 /usr/local/bin/node,先用命令: (which node )检查一下当前使用的 node 是否是这个路径下的。如上缘由,一般都是因为当前版本指定到了其他路径,更新下/etc/profile文件指定即可
方法二:
卸载 先node.js 在删除 关于 node 的文件
1、 yum remove nodejs npm -y 卸载node.js
2、find / -name node 查找node 文件
3、rm -rf /你要删除的路径或者文件
4、从新安装npm
yum -y install npm