简体   繁体   English

Angular 4 + AOT Webpack构建问题

[英]Angular 4 + AOT webpack build issue

I'm using Angular 4 and building project with webpack and AoT, but it's giving me this error: 我正在使用Angular 4并使用webpack和AoT构建项目,但这给了我这个错误:

ERROR in ng:///D:/proj/src/client/app/app.component.html (14,5): '$event' is declared but never used.

I'd made simplified project copy in plunker: http://embed.plnkr.co/RxY2mhfhJmcBFKjG70f0/ 我在plunker中制作了简化的项目副本: http ://embed.plnkr.co/RxY2mhfhJmcBFKjG70f0/

You can reproduce this issue with following steps: 您可以通过以下步骤重现此问题:

  1. Download project from the plunker: https://plnkr.co/edit/RxY2mhfhJmcBFKjG70f0?p=info 从the客下载项目: https ://plnkr.co/edit/RxY2mhfhJmcBFKjG70f0 ? p = info
  2. In project root npm i then npm run build:client or npm run build-v:client 在项目根目录npm i然后npm run build:clientnpm run build-v:client

If you change the src/client/app/app.component.html at line 13 like this: 如果像这样在第13行更改src/client/app/app.component.html

<li *ngFor="let hero of heroes" (click)="onSelect(hero, $event)" [class.selected]="hero === selectedHero">

the error will disappear. 错误将消失。 But this is a bad solution obviously. 但这显然是一个不好的解决方案。

Any ideas to solve the problem? 有解决问题的想法吗?

I think that AoT somehow compiles the template to some kind of intermediate resource where it adds that variable. 我认为AoT以某种方式将模板编译为某种中间资源,并在其中添加该变量。 But I can't find out how to manage/prevent/fix this. 但我找不到如何管理/预防/修复此问题。

The problem is in src/client/tsconfig-aot.json . 问题出在src/client/tsconfig-aot.json The "noUnusedParameters": true, should be removed. "noUnusedParameters": true,应删除。

Thanks for help with comments. 感谢您的评论帮助。 It took me to the right direction. 它带我去了正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM