Angular 11 – [HMR] 更新失败:NullInjectorError:没有 ApplicationRef 的提供者

所以我已经将一个 Angular 10 项目更新为一个 Angular 11 项目。

除了更换新的明亮闪亮的热模块外,一切正常。

所以我已经完成了所有步骤并且我有一个编译应用程序。使用 --hmr 标志时,一切看起来都不错。直到我来到浏览器并在控制台看到警告:

[WDS] App hot update... reloadApp.js:19
[HMR] Checking for updates on the server... log.js:24
[HMR] Update failed: NullInjectorError: No provider for ApplicationRef!
get@http://localhost:4200/vendor.js:23645:27
getToken@http://localhost:4200/vendor.js:80240:62
getapplicationRef@http://localhost:4200/vendor.js:80243:28
default_1/<@http://localhost:4200/vendor.js:80181:41
hotApplyInternal@http://localhost:4200/runtime.js:644:16
hotApply@http://localhost:4200/runtime.js:412:19
hotUpdateDownloaded/<@http://localhost:4200/runtime.js:387:22
invoke@http://localhost:4200/polyfills.js:9738:30
run@http://localhost:4200/polyfills.js:9497:47
scheduleResolveOrReject/<@http://localhost:4200/polyfills.js:10231:40
invoketask@http://localhost:4200/polyfills.js:9773:35
runTask@http://localhost:4200/polyfills.js:9541:51
drainmicroTaskQueue@http://localhost:4200/polyfills.js:9943:39
promise callback*schedulemicroTask@http://localhost:4200/polyfills.js:9926:32
scheduletask@http://localhost:4200/polyfills.js:9762:42
scheduletask@http://localhost:4200/polyfills.js:9584:47
schedulemicroTask@http://localhost:4200/polyfills.js:9604:29
scheduleResolveOrReject@http://localhost:4200/polyfills.js:10221:18
then@http://localhost:4200/polyfills.js:10353:44
hotUpdateDownloaded@http://localhost:4200/runtime.js:386:15
hotAddUpdateChunk@http://localhost:4200/runtime.js:362:13
webpackHotUpdateCallback@http://localhost:4200/runtime.js:58:29
@http://localhost:4200/soft-login-soft-login-module-ngfactory.4092c72c4d6fd794913e.hot-update.js:1:17

那是什么,我需要做什么来修复它?

我做了什么

  • ng update @angular/core @angular/cli
  • ng update @angular/material
  • ng update
  • 已删除package-lock.json and node_modules
  • 运行 npm cache clean --force 以清理 NPM 缓存
  • 运行 npm i 重新安装所有内容
fwangeling 回答:Angular 11 – [HMR] 更新失败:NullInjectorError:没有 ApplicationRef 的提供者

确保您没有禁用 Ivy。

我的 tsconfig.json

上有这个
...
"angularCompilerOptions": {
    ... other flags
    "enableIvy": false
  }

删除 "enableIvy": false 解决了问题

本文链接:https://www.f2er.com/1079961.html

大家都在问