npm 安装不起作用:“npm ERR!代码 ERR_SSL_WRONG_VERSION_NUMBER”

问题描述 投票:0回答:2

我无法为我的 React 应用程序安装模块,当我运行

npm i
时,它会执行以下操作:

npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\setprototypeof-b857a2ac\package.json'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\setprototypeof-b857a2ac\index.d.ts'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\setprototypeof-b857a2ac\index.js'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\setprototypeof-b857a2ac\LICENSE'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\rc-5aecd98b\test\ini.js'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\setprototypeof-b857a2ac\README.md'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\rc-5aecd98b\test\nested-env-vars.js'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\rc-5aecd98b\test\test.js'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\term-size-f230f088\vendor\windows\term-size.exe'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\ast-types-5383d6cc\def\type-annotations.js'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\ast-types-5383d6cc\def\typescript.js'
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code ERR_SSL_WRONG_VERSION_NUMBER
npm ERR! errno ERR_SSL_WRONG_VERSION_NUMBER
npm ERR! request to https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz failed, reason: 4376:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:308:
npm ERR!

我尝试重新安装 npm,它也做了同样的事情。我尝试了另一个项目,但遇到了同样的错误。我发现另一个问题,有人有同样的问题,但没有人回答。我什至尝试将 npm 注册表设置为

http://registry.npmjs.org
而不是
https://registry.npmjs.org
,并将
strict-ssl
选项设置为 false,但仍然不起作用。 我的 npm 版本是
6.14.13
,我的 Node 版本是
v14.17.1
。 有什么帮助吗? P.S.:我没有使用代理

node.js npm
2个回答
0
投票

快速解决方案是删除

node_modules
package-lock.json
,这样当您重新安装软件包时,它们会随
lockfileVersion@1
而不是
lockfileVersion@2
一起安装。

但我不会建议这种解决方案,就好像你在一个团队中工作一样,你会强迫其他人做同样的事情来解决它。

问题是npm版本

v6.x.x
支持
lockfileVersion@1
,而
v7.x.x
支持
lockfileVersion@2

因此,更好的解决方案是将您的 npm 版本更新到 v7 及更高版本。

在这里你可以找到一个有趣的相关讨论:有没有办法修复 package-lock.json lockfileVersion 以便 npm 使用特定格式?


0
投票

运行

npm i
命令时我也遇到了该错误。 删除
node_modules
package-lock.json
没有帮助。

我跑了

npm set strict-ssl false
,然后尝试跑
npm i
。 出现不同的错误:
ERR_SSL_CIPHER_OPERATION_FAILED
然后
npm set strict-ssl false
再次

然后再次

npm i
......并且成功了。但不知道为什么。

© www.soinside.com 2019 - 2024. All rights reserved.