我正在尝试在我的电脑中安装 Angular 5。一切都安装正确,但是当我使用“ng-serve”命令运行我的应用程序时,它显示以下错误。
You are running version v8.7.0 of Node.js, which is not supported by Angular CLI v6.
The official Node.js version that is supported is 8.9 and greater.
Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.
node.js 的当前版本是“8.7.0”,npm 是“6.0.0”。
经过大量搜索后,我按照以下步骤在 Windows 10 上更新我的 Node.js
npm cache clean -f
npm install -g n
n latest
但我无法使用此命令,它显示以下错误
C:\WINDOWS\system32>npm cache clean -f
npm WARN using --force I sure hope you know what you are doing.
C:\WINDOWS\system32>npm install -g n
npm ERR! code EBADPLATFORM
npm ERR! notsup Unsupported platform for [email protected]: wanted {"os":"!win32","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm ERR! notsup Valid OS: !win32
npm ERR! notsup Valid Arch: any
npm ERR! notsup Actual OS: win32
npm ERR! notsup Actual Arch: x64
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\HP\AppData\Roaming\npm-cache\_logs\2018-05-06T07_36_10_847Z-debug.log
如何将 Node.js 更新到最新版本才能运行我的 Angular5 应用程序?
您收到消息表明安装的节点版本不支持 Angular。 您需要做的是更新您的节点。 您使用的命令不是用于在 WINDOWS 上更新,而是在 Linux 和 MacO 上使用的命令 你应该使用这个命令:
npm install npm@latest -g
这里的问题是您的计算机中已经安装了 8.7.0 的节点版本。您必须先将其删除。
解决此问题的步骤。
1.检查环境变量中nodejs的路径
2.转到该路径并删除整个文件夹(旧节点js)
3.删除环境变量中的该路径
4.转到某个路径并在cmd中输入npm。你应该得到命令无法识别。
4.现在转到所需的路径并运行 npm install 命令。您的新版本的 Node js 将被更新。
希望我有帮助
我也遇到了这个问题,但我认为这是我的错误,可能是从错误的目录安装的,损坏了某些模块或其他什么。我通过查看 npm 日志并查看一些关于目录丢失不应该出现在列出的目录中的内容的奇怪消息来确定我的问题。
无论如何,我删除了根工作目录中的“node_modules”,然后运行:
npm uninstall npm -g
浏览到“%userprofile%\AppData\Local”并删除:
node-gyp
npm-cache
然后重新安装/更新npm:
npm install -g npm@latest
重新安装 ng-cli 并从 C:\Users***\AppData\Roaming 中删除 npm 和 npm-cache 修复了此问题;
更多详细信息可以在这里找到: https://stackoverflow.com/a/62184572/6792588
您可以下载 Windows Installer 并设置为新安装 https://nodejs.org/en/download/