【问题标题】:angular-cli: "SyntaxError: Unexpected token" when compiling for production and AOTangular-cli:为生产和 AOT 编译时出现“SyntaxError: Unexpected token”
【发布时间】:2017-01-29 11:07:56
【问题描述】:

我正在使用 angular2 typescript 并使用 angular-CLI 进行编译

当我尝试使用 AOT 编译和生产时 ng build --aot --prod 我无缘无故地收到错误:

ERROR in main.4b427a390fd79800862f.bundle.js from UglifyJs
SyntaxError: Unexpected token: name (UriPipe) [main.4b427a390fd79800862f.bundle.js:19,4]

但代码很好.. 当我为开发编译(没有 uglify)时,一切正常

(UriPipe 是我制作的一个管道,可以正常工作)

版本:

os: ubuntu 16.04 LTS / Windows 10 x64
browser: chrome v56
angular-cli: 1.0.0-beta.26
node: 6.9.4
npm: 3.10.10
typescript: 2.0.10
angular2: 2.3.1

【问题讨论】:

  • 你试过ng serve --aot在浏览器中查看堆栈跟踪吗?

标签: angular typescript webpack angular-cli uglifyjs


【解决方案1】:

我找到了答案。问题出在 tsconfig.json 中,目标设置为 es6,而 uglifyjs 仅适用于 es5

【讨论】:

  • 如果这回答了你的问题,你应该接受这个答案:)
  • 我在tsconfig.json中把es2015/es6的所有引用都改成了es5,还是不行。我需要更改模块和库还是只更改目标?
  • 成功了。我的项目中有 2 个 tsconfig.json 文件,看来我改错了。我都更新了,而且效果很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-17
  • 2018-12-15
  • 2018-12-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多