类型错误:angularCompiler.getNextProgram 不是函数

Thi*_*ana 14 typescript angular angular-ivy angular11

我在我的机器上使用 angular 11.2,我想运行一个 angular 12 项目。从 git 克隆后,我运行了以下命令。

  1. npm install
  2. ng serve

但是我遇到了以下错误并且无法运行该项目。我读了这个问题,但它对我不起作用。

Error: ./src/main.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
TypeError: angularCompiler.getNextProgram is not a function
    at C:\Users\thimira_p\Desktop\itrd\epic-itrda-web\node_modules\@ngtools\webpack\src\ivy\plugin.js:376:100
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Error: ./src/polyfills.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
TypeError: angularCompiler.getNextProgram is not a function
    at C:\Users\thimira_p\Desktop\itrd\epic-itrda-web\node_modules\@ngtools\webpack\src\ivy\plugin.js:376:100
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Error: (webpack)-dev-server/client?http://0.0.0.0:0&sockPath=/sockjs-node
Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
TypeError: angularCompiler.getNextProgram is not a function
    at C:\Users\thimira_p\Desktop\itrd\epic-itrda-web\node_modules\@ngtools\webpack\src\ivy\plugin.js:376:100
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

小智 10

升级@angular-devkit/build-angular@0.1100@angular-devkit/build-angular@12


and*_*tor 8

我在使用自定义 webpack.config的 Angular 应用程序中遇到了同样的问题-@angular-builders/custom-webpack作为依赖项。

Angular 和@angular-builders主要版本应该匹配。

通过更新@angular-builders/custom-webpack到最新版本解决:

npm install @angular-builders/custom-webpack@12.0.0


如果,在做安装后,你会得到这样的错误: An unhandled exception occurred: Cannot find module 'webpack',尝试删除package-lock.jsonnode_modules,做一个干净的安装。


Github 问题:https : //github.com/just-jeb/angular-builders/issues/981


小智 7

尝试删除

“aot”:真的

来自 angular.json