无法更新npm版本

kokeuurv  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(176)

我正在学习一门课程,我被指示降级我的npm版本,以便我和课程创建者都有相同的体验。
然而,当我试图运行一个正常的npm i时,我得到了这个错误:

npm WARN npm npm does not support Node.js v21.2.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/
npm ERR! cb.apply is not a function

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\97333\AppData\Roaming\npm-cache\_logs\2023-11-26T20_36

字符串
所以我决定回到我原来的版本,运行npm i -g npm@latest
得到了这个

npm WARN npm npm does not support Node.js v21.2.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/
(node:12004) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
WARNING: You are likely using a version of node-tar or npm that is incompatible with this version of Node.js.
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.

  #  npm[12004]:  at c:\ws\src\node_zlib.cc:585
  #  Assertion failed: args.Length() == 7 && "init(windowBits, level, memLevel, strategy, writeResult, writeCallback," " dictionary)"

----- Native stack trace -----

 1: 00007FF73C18C11B node::SetCppgcReference+13835
 2: 00007FF73C104826 DSA_meth_get_flags+76758
 3: 00007FF73C104C35 DSA_meth_get_flags+77797
 4: 00007FF73BFF0CD6 RSA_meth_get_flags+110726
 5: 00007FF6DCB8EF5F

----- JavaScript stack trace -----

1: Zlib (C:\Users\97333\AppData\Roaming\npm\node_modules\npm\node_modules\tar\node_modules\minizlib\index.js:130:19)
2: Unzip (C:\Users\97333\AppData\Roaming\npm\node_modules\npm\node_modules\tar\node_modules\minizlib\index.js:323:5)
3: write (C:\Users\97333\AppData\Roaming\npm\node_modules\npm\node_modules\tar\lib\parse.js:289:23)
4: ondata (node:internal/streams/readable:1007:22)
5: emit (node:events:519:28)
6: addChunk (node:internal/streams/readable:559:12)
7: readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
8: Readable.push (node:internal/streams/readable:390:5)
9: node:internal/streams/transform:178:12
10: PassThrough.enter code here_transform (node:internal/streams/passthrough:46:3)


有人知道如何解决这个问题吗

6kkfgxo0

6kkfgxo01#

npm是“Node Package Manager”,需要Node才能运行。降级到npm不支持的版本会导致它无法运行,正如终端中警告的那样。最简单的修复方法是卸载并重新安装NodeJS。
正如评论中所说:尝试使用Node的版本管理器。在Linux和Mac上,nvm非常好。在Windows上,我使用nvs。在所有平台上都有多种替代方案。
与问题无关,但作为问题的原因,值得探讨一些:
虽然NodeJS和NPM通常都有很好的版本控制,但并不是所有的开源软件都有,而且你可能会在课程中遇到更多来自示例代码的内部依赖关系的问题。当这种情况发生时,你可以尝试调试,但如果你刚刚开始,这将很难。获得退款并找到一个更好的课程并不感到羞愧。

相关问题