首页 > 解决方案 > Angular 在初始配置期间给出语法错误

问题描述

我正在尝试在 Windows 10 操作系统上创建 Angular 应用程序。以前当我尝试安装 Node.js 和 NPM 时,我得到“找不到未定义的“解决””。我通过将 Node.js 降级到 6.17 并将 NPM 降级到 3.10 来解决它。我现在可以下载 Angular CLI,但是当我使用“新”命令时,出现以下错误。

C:\Users\user_name\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng:23
  );
  ^

SyntaxError: Unexpected token )
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.runMain (module.js:611:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:160:9)

当我打开文件位置时,我得到以下信息:


#!/usr/bin/env node
'use strict';

// Provide a title to the process in `ps`.
// Due to an obscure Mac bug, do not start this title with any symbol.
try {
  process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
} catch (_) {
  // If an error happened above, use the most basic title.
  process.title = 'ng';
}

// This node version check ensures that extremely old versions of node are not used.
// These may not support ES2015 features such as const/let/async/await/etc.
// These would then crash with a hard to diagnose error message.
// tslint:disable-next-line: no-var-keyword
var version = process.versions.node.split('.').map(part => Number(part));
if (version[0] < 10 || version[0] === 11 || (version[0] === 10 && version[1] < 13)) {
  process.stderr.write(
    'Node.js version ' + process.version + ' detected.\n' +
    'The Angular CLI requires a minimum Node.js version of either v10.13 or v12.0.\n\n' +
    'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
  );

  process.exit(3);
}

require('../lib/init'); 

它抱怨 if 语句的括号。我试着去掉括号,它只会让情况变得更糟。解决这种情况的最佳方法是什么。以某种方式安装新版本的 Node 并解决“解决”错误或使用我手头的版本会更好吗?

标签: node.jsangularnpm

解决方案


推荐阅读