启动项目时在Angular 2中获取错误

时间:2017-02-20 06:51:06

标签: angular npm

我是角色2的新手。我已经设置了我的项目并试图通过npm启动它,以前它工作正常然后在我启动它的几天后,它在命令提示符中给出以下错误。

SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/ahmer/practice/gmail-angular2/node_modules/@ngtools/webpack/src/index.js:5:10)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/ahmer/practice/gmail-angular2/node_modules/angular-cli/models/webpack-build-typescript.js:3:17)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/ahmer/practice/gmail-angular2/node_modules/angular-cli/models/webpack-config.js:2:34)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/ahmer/practice/gmail-angular2/node_modules/angular-cli/tasks/build-webpack.js:6:24)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/ahmer/practice/gmail-angular2/node_modules/angular-cli/commands/build.js:4:23)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Class.module.exports.includedCommands (/home/ahmer/practice/gmail-angular2/node_modules/angular-cli/addon/index.js:21:16)
at /home/ahmer/practice/gmail-angular2/node_modules/angular-cli/ember-cli/lib/models/project.js:335:61
at Array.forEach (native)
at Project.addonCommands (/home/ahmer/practice/gmail-angular2/node_modules/angular-cli/ember-cli/lib/models/project.js:334:15)
at Project.eachAddonCommand (/home/ahmer/practice/gmail-angular2/node_modules/angular-cli/ember-cli/lib/models/project.js:369:30)
at module.exports (/home/ahmer/practice/gmail-angular2/node_modules/angular-cli/ember-cli/lib/cli/lookup-command.js:33:13)
at CLI.<anonymous> (/home/ahmer/practice/gmail-angular2/node_modules/angular-cli/ember-cli/lib/cli/cli.js:43:26)
at tryCatch (/home/ahmer/practice/gmail-angular2/node_modules/rsvp/dist/rsvp.js:538:12)
at invokeCallback (/home/ahmer/practice/gmail-angular2/node_modules/rsvp/dist/rsvp.js:553:13)
at publish (/home/ahmer/practice/gmail-angular2/node_modules/rsvp/dist/rsvp.js:521:7)
at flush (/home/ahmer/practice/gmail-angular2/node_modules/rsvp/dist/rsvp.js:2373:5)
at nextTickCallbackWith0Args (node.js:419:9)
at process._tickCallback (node.js:348:13)

知道怎么解决吗?

1 个答案:

答案 0 :(得分:0)

我相信您使用较旧的角度CLI版本创建了您的项目。 我将自己的角度cli版本更新为最新版本后,我自己也遇到了同样的错误。 Angular CLI在之前更新,因此需要节点版本6.9.0或更高版本以及npm版本3或更高版本。 https://github.com/angular/angular-cli#prerequisites

tldr:您必须更新节点版本