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

查看:98
本文介绍了从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 com/angular/angular/blob/master/packages/compiler-cli/src/ngtsc/resource_loader.ts#L111 尚不清楚模板网址与返回的Promise错误相关的方式.

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.

试图使用纯模板(无webpack)通过"templateUrl"使用一些标记模板将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天全站免登陆