如何在 Windows 上修复 'npm does not support Node.js v11.14.0 error'?

How to fix 'npm does not support Node.js v11.14.0 error' on Windows?

我正在配置我的 react-native 环境。我正在尝试 运行 Facebook Github 文档 here

中描述的 react-native 命令行

我已经安装了最新版本的 node.js 当我输入 C:\WINDOWS\system32>node -v 时返回 v11.14.

下载的 npm 包含在最新版本的 node.js 中。但是它只有 5.5.1。当我输入 C:\WINDOWS\system32>npm -v 结果是 5.5.1

这是代码

C:\WINDOWS\system32>npm install -g react-native-cli
npm WARN npm npm does not support Node.js v10.15.3
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! Cannot read property 'startsWith' of null

npm ERR! A complete log of this run can be found in:

当我尝试用 npm cache clean -f 清理缓存时,结果是这样

C:\WINDOWS\system32>npm cache clean -f
npm WARN npm npm does not support Node.js v10.15.3
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 WARN using --force I sure hope you know what you are doing.

编辑 以下代码是一些建议解决方案的结果

C:\WINDOWS\system32>npm install -g npm
npm WARN npm npm does not support Node.js v11.14.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! Cannot read property 'startsWith' of null

npm ERR! A complete log of this run can be found in:
C:\WINDOWS\system32>npm install -g npm-windows-upgrade
npm WARN npm npm does not support Node.js v11.14.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! Cannot read property 'startsWith' of null

npm ERR! A complete log of this run can be found in:
C:\WINDOWS\system32>npm install -g npm-windows-upgrade
npm WARN npm npm does not support Node.js v11.14.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! Cannot read property 'startsWith' of null

npm ERR! A complete log of this run can be found in:

我希望打开 npm 命令行界面。我尝试调用接口时收到错误消息。

您使用的是旧版本的 npm。请升级到最新版本

简单的解决方案是升级您的 npm 版本,或者第二种选择是降级您的节点版本。

从这里下载旧节点版本

https://nodejs.org/en/download/releases/

How do I update npm?

npm install -g npm

Please note that this command will remove your current version of npm. Make sure to use sudo npm install -g npm if on a Mac.

You can also update all outdated local packages by doing npm update without any arguments, or global packages by doing npm update -g.

Occasionally, the version of npm will progress such that the current version cannot be properly installed with the version that you have installed already. (Consider, if there is ever a bug in the update command.) In those cases, you can do this

npm install -g npm-windows-upgrade
npm-windows-upgrade

我从 C:\Users{name}\AppData\Roaming 中删除了节点和 npm。然后我重新安装了一个旧版本 node.js v10.15.3 和 npm 6.4.1.

这引发了一个不同的错误,所以我将关闭这个问题...

C:\>npm install -g expo-cli
npm ERR! Cannot read property 'startsWith' of null

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\dnort\AppData\Roaming\npm-cache\_logs19-04-15T06_32_09_154Z- 

debug.log

我在使用 npm 时遇到了同样的问题,所以我在考虑 npm 的替代方案。而且,你可以试试纱线。

首先,去https://nodejs.org/en/下载LTS版本的nodejs。

其次,去https://yarnpkg.com下载稳定版的msi文件

注意目前nodejs和yarn的版本分别是10.16.0 LTS和1.17.3。 安装后,您可以使用 yarn install 而不是 npm install.

安装您的项目包

最新版本也有同样的问题。 删除所有 NodeJS 安装。 目前 npm 支持 node js 版本 6、8、9、10、11。

转到 this 版本(或更旧)下载 msi 文件,然后执行 npm 安装。

安装当前的 NodeJS LTS 后,我仍然得到 npm does not support Node.js {version}.

我删除了 C:\Users\{user}\AppData\Roaming\npm\ 中的所有文件并且它有效。