在Angular 12和自定义Webpack时,可能会遇到'angularCompiler.getNextProgram is not a function”错误。此错误是由于自定义Webpack配置中缺少一些必需的库所致。
解决方法是在package.json文件中安装以下依赖项:
"@angular/compiler-cli": "^12.0.0",
"@angular/platform-server": "^12.0.0",
"@ngtools/webpack": "^12.0.0"
安装完毕后,在Webpack配置中添加以下代码片段:
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
module.exports = {
// ...
plugins: [
new AngularCompilerPlugin({
tsConfigPath: 'path/to/tsconfig.json',
// ...
})
]
};
其中tsConfigPath应该指向你的tsconfig.json文件的路径。
这些更改应该解决'angularCompiler.getNextProgram is not a function”错误。