-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Getting “inject() must be called from an injection context” after upgrading to Angular 11 #8447
Comments
can you elaborate in more detail what the step "2. Reference the API-Client in your Angular 11 Web-Application" means technically? maybe you can upload a demo repo on github. |
@macjohnny Hi! Of course.. well.. The API-Client is a compiled package which is located at "meditation-rest-client": "./generated/meditation-rest-client" This setup worked in Angular 9 and I am not sure what exactly change with Angular 11 here. On one side, I upgraded the OpenAPI tool-chain as stated, on the other side I upgraded my web-application to Angular 11. |
in the |
@macjohnny Interesting.. you are right. Indeed, there is one.. how did that get there? O_o This client gets generated at build-time. So.. in my Any idea how it got there? Maybe from a |
if you want to run the code of the compiled npm package, you would need to reference it in your
if you want to compile the generated code as part of your frontend-build, you can reference
but then you need to make sure the |
Just to clarify: This here is already the
Basically:
That's how I always did it (Angular 9). |
And I already tried to use |
yes, but my guess would be that Please try deleting |
another source of issues could be symlinks |
@macjohnny I'll have to make a few changes to make sure this works but from the first look.. it seems the Thank you so far. Thanks a lot! :) |
@macjohnny Just a quick question.. The problem with copying The error was
This was why I compiled the API-Client beforehand and then copied the |
you should not place the
this way, you can compile the generated code along with your frontend code, without the need to compile the npm package separately. |
I also added an answer to https://stackoverflow.com/questions/65709951/getting-inject-must-be-called-from-an-injection-context-after-upgrading-to-a/65738925 if this resolves your issue, please close the issue and if you like it, mark the answer as accepted. |
No, no. I never put it there. It's always in
comes if I put the non-compiled version of |
Could you please post more details about the error that occurs, and more details about which code is placed where? |
So, this here is the generated (non-compiled) version of What I used to do is compile this beforehand and copy the content of
This meant, that I was able to import things from there like this: import {Track} from 'meditation-rest-client'; And this seems to work but (for some reason) I have to remove this rouge You suggested, however, do reference the non-compiled version. That would be (something like) this:
But, if I reference the non-compiled version, I will get
when running
|
This here is the I am sure this didn't happen previously but as you can see, there is now a This rouge
having reference (in package.json)
And I am 90% sure this was not an issue in Angular 9 (?) |
to avoid the
the simplest way would be to copy the entire content of otherwise you would need to add |
Okay. So, with tsconfig.json
Does not work with imports like This is the same for copying the code directly into So far the only way that "works" is to link the compiled version of the code but then the question would be: "Where is the rouge |
Here is what I tried to reproduce your situation:
This compiles successfully. |
I think I've got it. Instead of /* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compileOnSave": false,
"compilerOptions": {
..
"paths": {
"meditation-rest-client": ["./generated/meditation-rest-client"]
}
}
} This seems to work now! :) |
To avoid having to use relative paths, you can add a path mapping to your
I dont know why this happens, maybe some |
so can you close this issue as it is resolved? |
Yeah, thanks a lot man! Do you have a "buy me a coffee"-button somewhere? :D Yeah, this issue is resolved! Thanks a hundred times! |
glad it works. |
Falls ich mal in der Schweiz bin ;) |
Description
After having generated an API-client under the
org.openapi.generator:5.0.0
using theorg.springdoc.openapi-gradle-plugin:1.3.0
, my web application crashes, giving me the following error:openapi-generator version
5.0.0
OpenAPI declaration file content or url
Generation Details
I am using the
openapi-generator-gradle-plugin
:Steps to reproduce
ng serve
Related issues/PRs
I have tried to apply suggestions from
without success.
The text was updated successfully, but these errors were encountered: