angular / angular/angular-cli

Show compile-time error/warning for using `@angular/compiler` with optimized builds

未关闭
#19,016 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
area: @angular-devkit/build-angular devkit/build-angular:browser feature feature: insufficient votes severity1: confusing workaround2: non-obvious
主要语言
TypeScript
星标
27k
派生
11.8k
平均合并
14 小时 23 分钟
30 天内合并 PR
162

描述

# 🚀 Feature request

### Command (mark with an `x`)
- [X] build

### Description
Currently it is possible to have a configuration which uses AOT compilations but also JIT during runtime and attempts to run build optimizer on the results. This doesn't really work and isn't supported, leading to awkward error messages, which can be confusing to users (see #17663).

### Describe the solution you'd like
Ideally, the CLI would detect this case and error out if an import for `@angular/compiler` is found in user code with build optimizer enabled. We should display a more precise warning/error about this case to better explain to the users why JIT + build optimizer doesn't work and what they can to do fix it.

### Describe alternatives you've considered
Currently this is a runtime error with a poor message.

```
main.7000374ef126bad8069c.js:1 ERROR Error: Uncaught (in promise): Error: Angular JIT compilation failed: '@angular/compiler' not loaded!
- JIT compilation is discouraged for production use-cases! Consider AOT mode instead.
- Did you bootstrap using '@angular/platform-browser-dynamic' or '@angular/platform-server'?
- Alternatively provide the compiler with 'import "@angular/compiler";' before bootstrapping.
Error: Angular JIT compilation failed: '@angular/compiler' not loaded!
- JIT compilation is discouraged for production use-cases! Consider AOT mode instead.
- Did you bootstrap using '@angular/platform-browser-dynamic' or '@angular/platform-server'?
- Alternatively provide the compiler with 'import "@angular/compiler";' before bootstrapping.
at Ae (main.7000374ef126bad8069c.js:1)
at Function.get (main.7000374ef126bad8069c.js:1)
at St (main.7000374ef126bad8069c.js:1)
at new Af (main.7000374ef126bad8069c.js:1)
at ud (main.7000374ef126bad8069c.js:1)
at dd (main.7000374ef126bad8069c.js:1)
at e.md [as compileModuleAndAllComponentsAsync] (main.7000374ef126bad8069c.js:1)
at e. (main.7000374ef126bad8069c.js:1)
at Generator.next ()
at main.7000374ef126bad8069c.js:1
at T (polyfills.a8d522dff2c1a5c4b9db.js:1)
at polyfills.a8d522dff2c1a5c4b9db.js:1
at a (main.7000374ef126bad8069c.js:1)
at l.invoke (polyfills.a8d522dff2c1a5c4b9db.js:1)
at Object.onInvoke (main.7000374ef126bad8069c.js:1)
at l.invoke (polyfills.a8d522dff2c1a5c4b9db.js:1)
at i.run (polyfills.a8d522dff2c1a5c4b9db.js:1)
at polyfills.a8d522dff2c1a5c4b9db.js:1
at l.invokeTask (polyfills.a8d522dff2c1a5c4b9db.js:1)
at Object.onInvokeTask (main.7000374ef126bad8069c.js:1)
```

贡献指南

打开贡献指南

调研方向

首先追踪 Angular CLI 针对优化构建的构建路径,以及它如何处理用户对 @angular/compiler 的导入。将完成定义为:在构建过程中检测到这种组合,并报告一条准确的警告或错误,说明 JIT/build-optimizer 的不兼容性以及可用的修复方法。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
build-system, cli
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。