从 Angular 7 迁移后,Angular 8 无法构建 [英] Angular 8 fails to build after migration from Angular 7

查看:45
本文介绍了从 Angular 7 迁移后,Angular 8 无法构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我将我的项目迁移到 Angular 8 后,构建失败并出现这个奇怪的错误:

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.

因此,最初它无法在 Angular Compiler 资源加载器的这一特定行加载 templateUrl 中指定的模板文件:https://github.com/angular/angular/blob/master/packages/compiler-cli/src/ngtsc/resource_loader.ts#L111并且不清楚模板 url 以何种方式与返回的承诺错误相关.

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

通过 ng update 命令从 Angular 7 迁移,因此变化很小.

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

我正在使用与 Angular 7 配合良好的 webpack 4,可能应该更改一些 webpack 选项.

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.

尝试通过`templateUrl'使用一些标记模板,使用纯(无 webpack)Angular 从 7 迁移到 8 来重现它.

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

推荐答案

所以 webpack 使用了 @ngtools/webpack 插件,其中包括加载 Angular 模板.

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

我将 @ngtools/webpack 更新为 @angular/cli - ^8.3.15 的版本 - 并修复了初始错误.

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

但仍然存在一些 TypeScript 错误,ng update 命令更新了 TypeScript 版本,但它错过了两个应该更新到更高版本的库:

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.

这篇关于从 Angular 7 迁移后,Angular 8 无法构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆