Angular 8 fails to build after migration from Angular 7

天大地大妈咪最大 提交于 2019-12-24 00:33:33

问题


After I migrated my project to Angular 8, the build fails with this strange error:

    ERROR in HostResourceLoader: loader(C:/myapp/cli/src/app/pages/user-home/user-home.component.html) returned a Promise 
    i 「wdm」: Failed to compile.

but when I save any file the application builds ok after recompiling:

i 「wdm」: Compiling...
i 「wdm」: Compiled successfully.

So initially it fails to load the template file specified in templateUrl at this specific line in Angular Compiler resource loader: https://github.com/angular/angular/blob/master/packages/compiler-cli/src/ngtsc/resource_loader.ts#L111 and it is unclear in a what way the template url relates to a returned promise error.

What could be wrong and what does that specific error mean? I guess it is some bug in the resource loader since recompiling on the fly works but the initial build fails.

UPD

Migrated from Angular 7 via ng update command, so changes are minimal.

I'm using webpack 4 that works fine with Angular 7, possibly some webpack options should be changed.

It is unclear what the root cause of the error is from the error description. Looking into the source of the compiler shed no light.

Tried to reproduce it with pure (no webpack) Angular migrated from 7 to 8 using some markup templates via `templateUrl'.


回答1:


So webpack uses @ngtools/webpack plugin which, among other things, loads Angular templates.

I updated @ngtools/webpack to the version of @angular/cli - ^8.3.15 - and that fixed the initial error.

But still there were some TypeScript errors, ng update command updated TypeScript version but it missed two libs that should be updated too to later versions:

"@types/node": "^10.17.2"
"tslib": "^1.10.0"

Then my project ran successfully.



来源:https://stackoverflow.com/questions/58598031/angular-8-fails-to-build-after-migration-from-angular-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!