Angular CLI停止工作-意外令牌{ [英] Angular CLI stopped working - Unexpected token {
问题描述
我使用Angular CLI创建了一段时间的项目,并且运行良好.但是,当我今天尝试创建一个新项目时,在尝试为其提供服务时出现错误.
I used Angular CLI to create projects for a while and it was working fine. But when I tried to create a new project today I got an error when trying to serve it.
ng serve
Unexpected token {
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
...
这是完整的堆栈跟踪 http://pastebin.com/71qU3G64
如果我删除node_modules目录并从旧项目中复制它,那么它会起作用,但这不是一个长期解决方案.
If I delete the node_modules directory and copy it from an old project it works, but that is not a long term solution.
推荐答案
现在可以正常工作了
- 根据同类用户的建议更新节点
- 更新Angular CLI https://github.com/angular/angular-cli #updating-angular-cli
要使我的旧项目在进行这些更改后能够正常工作,我必须执行以下操作(某些步骤来自上面的链接).
For my old project to work after these changes I had to do the following (some of the steps are from the link above).
- rmdir/s node_modules
- rmdir/s dist
- npm install --save-dev @ angular/cli @ latest
- npm安装
- ng更新
- 按照此处的建议更新package.json
- 再次安装npm
- rmdir /s node_modules
- rmdir /s dist
- npm install --save-dev @angular/cli@latest
- npm install
- ng update
- Update package.json as suggested here Getting error on ng serve: ERROR in Cannot read property 'listLazyRoutes' of undefined
- npm install (again)
此更新适用于我的大多数项目,但我仍然遇到一个问题
This update worked for most of my projects but I still have an issue with one
ng serve
patterns.map is not a function
TypeError: patterns.map is not a function
at GlobCopyWebpackPlugin.apply (C:\Users\jhertz\Workspaces\eclipsekatujo\ibi\src\app\node_modules\@angular\cli\plugins\glob-copy-webpack-plugin.js:25:29)
at Compiler.apply (C:\Users\jhertz\Workspaces\eclipsekatujo\ibi\src\app\node_modules\tapable\lib\Tapable.js:306:16)
at webpack (C:\Users\jhertz\Workspaces\eclipse-katujo\ibi\src\app\node_modules\webpack\lib\webpack.js:32:19)
at Class.run (C:\Users\jhertz\Workspaces\eclipse-katujo\ibi\src\app\node_modules\@angular\cli\tasks\serve.js:63:27)
at checkExpressPort.then.then (C:\Users\jhertz\Workspaces\eclipse-katujo\ibi\src\app\node_modules\@angular\cli\commands\serve.js:84:26)
at process._tickCallback (internal/process/next_tick.js:103:7)
通过更新项目文件夹中的angular-cli.json解决了上述错误.
The above error got solved by updating the angular-cli.json in the project folder.
== Old ==
"assets": "assets",
== New ==
"assets": ["assets"]
这篇关于Angular CLI停止工作-意外令牌{的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!