ng build
或者 ng deploy
时遇到如下错误:An unhandled exception occurred: The 'buildOptimizer' option cannot be used without 'aot'.
或其变体,那么以下的解决方法对我有效(向下滚动):ng build
或者 ng deploy
时遇到如下错误:An unhandled exception occurred: The 'buildOptimizer' option cannot be used without 'aot'.
或其变体,那么以下的解决方法对我有效(向下滚动):angular.json
文件"buildOptimizer"
改为 true
并添加 "aot"
也改为 true
现在应该可以使用上述命令了。
补充说明: 如果你在执行 ng serve
或 ng test
时遇到该问题,你可以尝试将步骤2中的 build
替换为分别的 serve
或 test
(免责声明:我没有测试过)。
当我从Angular 11升级到Angular 13时,在运行ng serve
命令期间出现了这个错误。为了解决它,我创建了一个全新的Angular项目,并使用"@angular/cli"模仿了新项目中的angular.json
。
在angular.json
的projects>MY_PROJECT_NAME>architect>build>configurations
中添加了一个带有JSON的development
。
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
添加了...serve>配置
"development": {
"browserTarget": "hasap:build:development"
}
...serve>
后添加了 "defaultConfiguration": "development"
您可以从我的提交https://github.com/canbax/hasap/commit/9c0fc95fc244d35b2d7ee70c7048f6b38bd213b5中查看更改的详细信息
angular.json
中使用不同的配置解决了它!非常感谢! - Camille你需要在 angular.json 中启用 AOT 编译
将其更改为 true
构建{ "aot": true, ... }
我曾经遇到过这个错误信息,但是我的情况是在Angular项目中尝试设置Cypress。
我通过在angular.json文件中的projects.private-sellers-spa.architect.cypress-open.options和projects.private-sellers-spa.architect.cypress-run.options中添加以下配置来解决这个问题,具体如下:
"buildOptimizer": true,
"aot": true
我使用生产配置来运行我的项目
ng serve -o --ssl true --configuration production
这将使用buildOptimizer和aot问题。
ng update
。 这对我们有帮助。 - Shafiq Jethang serve
得到错误。 - canbax