question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Getting “inject() must be called from an injection context” after upgrading to Angular 11

See original GitHub issue
Description

After having generated an API-client under the org.openapi.generator:5.0.0 using the org.springdoc.openapi-gradle-plugin:1.3.0, my web application crashes, giving me the following error:

main.ts:12 Error: inject() must be called from an injection context
    at injectInjectorOnly (core.js:4901)
    at Module.ɵɵinject (core.js:4911)
    at Object.ApiModule_Factory [as factory] (meditation-rest-client.js:2885)
    at R3Injector.hydrate (core.js:11158)
    at R3Injector.get (core.js:10979)
    at core.js:11016
    at Set.forEach (<anonymous>)
    at R3Injector._resolveInjectorDefTypes (core.js:11016)
    at new NgModuleRef$1 (core.js:25046)
    at NgModuleFactory$1.create (core.js:25100)
openapi-generator version

5.0.0

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: OpenAPI definition
  version: v0
servers:
- url: http://127.0.0.1:8080
  description: Generated server url
paths:
  // ...
Generation Details

I am using the openapi-generator-gradle-plugin:

openApiGenerate {
    generatorName = 'typescript-angular'
    inputSpec = swaggerFilePath
    outputDir = apiClientOutputDir
    configOptions = [
            npmName   : 'meditation-rest-client',  // Api-client name
            npmVersion: '0.0.1',                   // Api-client version
            ngVersion : '11.0.6'
    ]
}
Steps to reproduce
  1. Build an API-Client from a Spring Boot Application
  2. Reference the API-Client in your Angular 11 Web-Application
  3. ng serve
  4. Find the error in your console
Related issues/PRs

I have tried to apply suggestions from

without success.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:26 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
falk-stefancommented, Jan 15, 2021

Falls ich mal in der Schweiz bin 😉

1reaction
macjohnnycommented, Jan 15, 2021

glad it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: inject() must be called from an injection context | Angular
Error: inject() must be called from an injection context ... I am trying to use AngularJS Grid, but getting the error and data...
Read more >
inject() must be called from an injection context at ... - You.com
When I build the library, and try to use the pipe it in the app. I get an "Error: inject() must be called...
Read more >
After Updating Angular From 8 To 11 Got Error In Ssr - ADocLib
After Updating Angular From 8 To 11 Got Error In Ssr: "Error: Inject() Must Be Called From An Injection Context". This subscription function...
Read more >
SSR Error: inject() must be called from an injection context
SSR Error: inject() must be called from an injection context. AngularJS ... Bug, feature request, or proposal: Bug ...
Read more >
[SOLVED] properly understanding inject in angular14 – inject() must ...
... inject in angular14 – inject() must be called from an injection context ... before when i tried to have a supporting function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found