【问题标题】:why are there typescript errors I only see in "ng build --prod" but not in "ng build" or "ng serve"?为什么我只在“ng build --prod”中看到打字稿错误,但在“ng build”或“ng serve”中没有看到?
【发布时间】:2021-08-16 19:14:03
【问题描述】:

在我的 Angular 11 应用程序中,ng serveng build 不会报告任何错误。但是在构建服务器上发生npm run ng build -- --prod --output-hashing=all,我突然看到一个错误:

Error: src/app/administration/clients/licensing-client.ts:7:15 - error TS6133: 'tap' is declared but its value is never read.

7 import { map, tap } from 'rxjs/operators';
                ~~~

我的问题是,为什么我做ng serve 时还没有报告这个错误?这些不同的配置有什么不同吗?

【问题讨论】:

  • --prod 进行完整的生产构建,这可以实现额外的签入和验证。 serve 并且在没有生产的情况下构建只是做一些控制,并且可能会为无效的打字稿发出 javascript,随后会出现 runtme 错误。

标签: typescript angular-cli ng-build


【解决方案1】:

你能分享你的angular.jsontsconfig.json吗?

产生此错误的tsconfig.json 编译器选项是

"compilerOptions": {
...
   "noUnusedLocals": true,
...
}

关于为什么它出现在生产模式而不是开发模式:

可能是 AOT 编译器和 buildOptimization,特别是如果它在生产模式下打开,在开发模式下关闭。尝试为所有模式打开 AOT,但为开发模式禁用 buildOptimization。否则,您将在开发时打开生产模式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    • 1970-01-01
    • 2020-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多