【Angular/node.js】当尝试创建一个新的项目时,检测到了Node.js的版本为v16.1.0。Angular CLI要求Node.js的最低版本为v12.20、v14.15或v16.10,请进行更新,否则无法执行…
假设
在创建新的Angular应用程序时,我输入了”ng new app-name”命令,但出现了以下错误。
Node.js version v16.1.0 detected.
The Angular CLI requires a minimum Node.js version of either v12.20, v14.15, or v16.10.
Please update your Node.js version or visit https://nodejs.org/ for additional instructions.
操作系统:MacOS BigSur(11.6)
Node.js:nodenv(brew)
尝试过的东西
按照错误提示的指示,我暂时将Node的版本切换为v16.10试了一下。
$ nodenv local 16.1.0
$ nodenv versions
12.2.0
12.18.3
14.15.5
* 16.1.0 (set by /Users/***/angular/.node-version)
再次尝试执行ng new,但结果并没有改变。
结论 (jié
原因可能是因为node或npm的版本过新,也可能原因不明。
执行npm install -g @angular/cli时,出现了这样的消息,但我忽略了它。
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '@angular/cli@13.0.4',
npm WARN EBADENGINE required: {
npm WARN EBADENGINE node: '^12.20.0 || ^14.15.0 || >=16.10.0',
npm WARN EBADENGINE npm: '^6.11.0 || ^7.5.6 || >=8.0.0',
npm WARN EBADENGINE yarn: '>= 1.13.0'
npm WARN EBADENGINE },
npm WARN EBADENGINE current: { node: 'v16.1.0', npm: '8.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '@angular-devkit/architect@0.1300.4',
npm WARN EBADENGINE required: {
npm WARN EBADENGINE node: '^12.20.0 || ^14.15.0 || >=16.10.0',
npm WARN EBADENGINE npm: '^6.11.0 || ^7.5.6 || >=8.0.0',
npm WARN EBADENGINE yarn: '>= 1.13.0'
npm WARN EBADENGINE },
npm WARN EBADENGINE current: { node: 'v16.1.0', npm: '8.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '@angular-devkit/core@13.0.4',
npm WARN EBADENGINE required: {
npm WARN EBADENGINE node: '^12.20.0 || ^14.15.0 || >=16.10.0',
npm WARN EBADENGINE npm: '^6.11.0 || ^7.5.6 || >=8.0.0',
npm WARN EBADENGINE yarn: '>= 1.13.0'
npm WARN EBADENGINE },
npm WARN EBADENGINE current: { node: 'v16.1.0', npm: '8.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '@angular-devkit/schematics@13.0.4',
npm WARN EBADENGINE required: {
npm WARN EBADENGINE node: '^12.20.0 || ^14.15.0 || >=16.10.0',
npm WARN EBADENGINE npm: '^6.11.0 || ^7.5.6 || >=8.0.0',
npm WARN EBADENGINE yarn: '>= 1.13.0'
npm WARN EBADENGINE },
npm WARN EBADENGINE current: { node: 'v16.1.0', npm: '8.2.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '@schematics/angular@13.0.4',
npm WARN EBADENGINE required: {
npm WARN EBADENGINE node: '^12.20.0 || ^14.15.0 || >=16.10.0',
npm WARN EBADENGINE npm: '^6.11.0 || ^7.5.6 || >=8.0.0',
npm WARN EBADENGINE yarn: '>= 1.13.0'
npm WARN EBADENGINE },
npm WARN EBADENGINE current: { node: 'v16.1.0', npm: '8.2.0' }
npm WARN EBADENGINE }
现有版本是
current: { node: 'v16.1.0', npm: '8.2.0' }
并且,看起来 npm 的版本不受支持。
npm: '^6.11.0 || ^7.5.6 || >=8.0.0'
所以,我們需要降低npm的版本,因為npm的版本似乎與node有關聯,所以我們暫時將node的版本降至14.15.5。
nodenv local 14.15.5
只需提供一种选项:再一次、再次。
npm install -g @angular/cli
ng new app
刚刚完成,Angular应用程序顺利创建完成。