为什么我只在 "ng build --prod" 中看到打字稿错误,而在 "ng build" 或 "ng serve" 中看不到?
why are there typescript errors I only see in "ng build --prod" but not in "ng build" or "ng serve"?
在我的Angular 11 应用程序中,ng serve
和ng 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
时没有报告此错误?这些不同的配置有什么不同吗?
你能分享你的 angular.json
和 tsconfig.json
吗?
产生这个错误的tsconfig.json
编译器选项是
"compilerOptions": {
...
"noUnusedLocals": true,
...
}
关于为什么它在生产模式下,而不是在开发模式下:
可能是AOT编译器和buildOptimization,特别是生产模式开启,开发模式关闭。尝试为所有模式打开 AOT,但为开发模式禁用 buildOptimization。否则你将在开发时打开生产模式。
在我的Angular 11 应用程序中,ng serve
和ng 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
时没有报告此错误?这些不同的配置有什么不同吗?
你能分享你的 angular.json
和 tsconfig.json
吗?
产生这个错误的tsconfig.json
编译器选项是
"compilerOptions": {
...
"noUnusedLocals": true,
...
}
关于为什么它在生产模式下,而不是在开发模式下:
可能是AOT编译器和buildOptimization,特别是生产模式开启,开发模式关闭。尝试为所有模式打开 AOT,但为开发模式禁用 buildOptimization。否则你将在开发时打开生产模式。