Node.js 升级后导致 npm 升级失败

由于 Node.js 很长时间没更新了,所以今天准备更新到最新版本。虽然,Node.js 更新成功了,但是 npm 没有更新,还是 5.5.1 版本,最新版本已经到 6.9.0 了。所以,运行更新 npm 命令npm install -g npm出现如下错误。

  1. npm WARN npm npm does not support Node.js v10.16.0
  2. npm WARN npm You should probably upgrade to a newer version of node as we
  3. npm WARN npm can't make any promises that npm will work with this version.
  4. npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
  5. npm WARN npm You can find the latest version at https://nodejs.org/
  6. WARNING: You are likely using a version of node-tar or npm that is incompatible with this version of Node.js.
  7. Please use either the version of npm that is bundled with Node.js, or a version of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) that is compatible with Node.js 9 and above.
  8. npm[5872]: c:\ws\src\node_zlib.cc:551: Assertion `args.Length() == 7 && "init(windowBits, level, memLevel, strategy, writeResult, writeCallback," " dictionary)"' failed.
  9. 1: 00007FF64B6FC6AA v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4506
  10. 2: 00007FF64B6D7416 node::MakeCallback+4534
  11. 3: 00007FF64B6D74CF node::MakeCallback+4719
  12. 4: 00007FF64B63653D v8::internal::ParseInfo::end_position+93005
  13. 5: 00007FF64BC04382 std::vector<v8::internal::compiler::MoveOperands * __ptr64,v8::internal::ZoneAllocator<v8::internal::compiler::MoveOperands * __ptr64> >::_Umove+79442
  14. 6: 00007FF64BC0580D std::vector<v8::internal::compiler::MoveOperands * __ptr64,v8::internal::ZoneAllocator<v8::internal::compiler::MoveOperands * __ptr64> >::_Umove+84701
  15. 7: 00007FF64BC04866 std::vector<v8::internal::compiler::MoveOperands * __ptr64,v8::internal::ZoneAllocator<v8::internal::compiler::MoveOperands * __ptr64> >::_Umove+80694
  16. 8: 00007FF64BC0474B std::vector<v8::internal::compiler::MoveOperands * __ptr64,v8::internal::ZoneAllocator<v8::internal::compiler::MoveOperands * __ptr64> >::_Umove+80411
  17. 9: 000002CC16CDC5C1

原因是,由于先升级了 Node.js 到 v10.16.0 版本,导致低版本的 npm 不支持高版本的 Node.js ,所以就运行错误了。

之后,尝试如何升级 npm 到最新版本,但是,没有成功啊…

所以,转变思路,把 npm 卸载,执行命令npm uninstall npm -g

卸载成功后,执行命令npm -v,发现 npm 版本已经是 6.9.0 了。我卸载后并没有重新安装 npm ,应该是卸载时更新了系统环境变量,导致随 Node.js 安装的最新版 npm 启用了。目前,只了解到此,如有新发现再更新。

系统环境和操作过程:

  • 操作系统:Windows 10 专业版
  • 升级方式:先卸载低版本 Node.js ,在开始菜单中选择 Uninstall Node.js 。然后在 Node.js 官网中下载 Windows 安装包,版本为当前长期支持版:10.16.0 (包含 npm 6.9.0),最后安装即可。
  • 卸载 npm :在 cmd 命令行中,执行卸载命令 npm uninstall npm -g
  • 执行命令 npm -v 查看 npm 版本为 6.9.0 。

(完)