簡體   English   中英

錯誤:必須從注入上下文調用注入() - 將 angular 8 升級到 9

[英]Error: inject() must be called from an injection context - Upgraded angular 8 to 9

我在啟用 Ivy 的情況下將我的 angular 應用程序從 8 升級到了 9。 現在應用程序正在正確構建,但是當我執行服務時,我在控制台中遇到錯誤 -

Error: inject() must be called from an injection context
    at injectInjectorOnly (VM29 vendor.js:32922)
    at Module.ɵɵinject (VM29 vendor.js:32933)
    at Object.A11yModule_Factory [as factory] (VM29 vendor.js:8401)
    at R3Injector.push.../../node_modules/@angular/core/__ivy_ngcc__/fesm5/core.js.R3Injector.hydrate (VM29 vendor.js:195954)
    at R3Injector.push.../../node_modules/@angular/core/__ivy_ngcc__/fesm5/core.js.R3Injector.get (VM29 vendor.js:195771)
    at VM29 vendor.js:195809
    at Set.forEach (<anonymous>)
    at R3Injector.push.../../node_modules/@angular/core/__ivy_ngcc__/fesm5/core.js.R3Injector._resolveInjectorDefTypes (VM29 vendor.js:195809)
    at new NgModuleRef$1 (VM29 vendor.js:209242)
    at NgModuleFactory.push.../../node_modules/@angular/core/__ivy_ngcc__/fesm5/core.js.NgModuleFactory.create (VM29 vendor.js:209302)

Angular:

"@angular-devkit/build-angular": "0.901.1",
"@angular-devkit/build-ng-packagr": "~0.901.1",
"@angular/cli": "^9.0.1",
"@angular/compiler-cli": "^9.1.1",

任何人有任何想法? 任何幫助將不勝感激。

我不知道根本原因和發生了什么。 我剛剛刪除了工作區,git 再次克隆了項目,這個問題就消失了。 奇怪的!!

我們最近注意到了這個問題,我們希望這個解決方案對某人有所幫助。

在我們的例子中,這個問題是在導入特定的 Angular 庫(自定義)時發生的。

解決方案是在導入庫的項目的angular.json文件中將preserveSymlinks設置為true

$.projects.<<PROJECT_NAME>>.architect.build.options.preserveSymlinks: true

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM