Skip to content
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

[REQ] Please Support Angular 9 #5246

Closed
eiswind opened this issue Feb 8, 2020 · 16 comments · Fixed by #5370
Closed

[REQ] Please Support Angular 9 #5246

eiswind opened this issue Feb 8, 2020 · 16 comments · Fixed by #5370

Comments

@eiswind
Copy link

eiswind commented Feb 8, 2020

Is your feature request related to a problem? Please describe.

Angular 9 has new requirements on typescript and rxjs that require updates.

@azimuthdeveloper
Copy link

azimuthdeveloper commented Feb 10, 2020

Is this just as simple as updating the generator to reference Typescript >= 3.6.4 and rxjs? Or is more required? If it's that simple I can submit a PR for this issue as I'm keen to get it resolved also.

EDIT: Seems like its more than just that, I don't think the openapi generators work with AOT.

App startup asplodes with inject() must be called from an injection context

@macjohnny
Copy link
Member

macjohnny commented Feb 10, 2020

@eiswind
Copy link
Author

eiswind commented Feb 10, 2020

I also updated
"ng-packagr": "^9.0.0"

@lewcianci Your error inject() must be called from an injection context must be something different.

At my side everything works fine now with a manually updated package.json.

@ltomes
Copy link

ltomes commented Feb 18, 2020

@eiswind so you updated your typescript, rxjs, and ng-packagr versions? Could you list the versions you are using?

I updated all angular versions as well ( but I believe it takes the value from the command line anyway), and although I can build the module, when I include it in my application, and use it I get cyclic dependency errors

Error: Cannot instantiate cyclic dependency! InjectionToken HTTP_INTERCEPTORS
    at throwCyclicDependencyError (core.js:7986)
    at R3Injector.hydrate (core.js:16761)
    at R3Injector.get (core.js:16526)
    at HttpInterceptingHandler.handle (http.js:2865)
    at MergeMapSubscriber.project (http.js:1665)
    at MergeMapSubscriber._tryNext (mergeMap.js:46)
    at MergeMapSubscriber._next (mergeMap.js:36)
    at MergeMapSubscriber.next (Subscriber.js:49)
    at Observable._subscribe (subscribeToArray.js:3)
    at Observable._trySubscribe (Observable.js:42)

There is a chance I am still just on the wrong rxjs version (6.5.4) or some other dependency.

Generate command:

generate -i ./v3.yaml -g typescript-angular -o src --package-name <name-here> --enable-post-process-file --additional-properties=useSingleRequestParameter=true,taggedUnions=true,ngVersion=9.0.1,npmName=<nameHere>,supportsES6=true,withInterfaces=true,enablePostProcessFile=true

Other details
@openapitools/openapi-generator-cli version: 1.0.10-4.2.3

P.S. Also note that this application does use HTTP_INTERCEPTORS, so this could be an issue specific to an angular 9 application with custom interceptors, that are using a module generated by open-api.

@eiswind
Copy link
Author

eiswind commented Feb 18, 2020

This worked at my side:

"peerDependencies": {
    "@angular/core": "^9.0.0",
    "@angular/common": "^9.0.0",
    "@angular/compiler": "^9.0.0",
    "core-js": "^2.4.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "^6.5.0"
  },
  "devDependencies": {
    "@angular/common": "^9.0.0",
    "@angular/compiler": "^9.0.0",
    "@angular/compiler-cli": "^9.0.0",
    "@angular/core": "^9.0.0",
    "@angular/platform-browser": "^9.0.0",
    "ng-packagr": "^9.0.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "^6.5.0",
    "tsickle": "^0.35.0",
    "typescript": ">=3.6.4 <3.8.0",
    "zone.js": "^0.9.1"
  },

@ltomes
Copy link

ltomes commented Feb 18, 2020

Thanks for sharing the versions you are using. I will try going to rx 6.5.0+ and see if that improves anything.

My issue seems to be around importing HTTP_INTERCEPTORS into app.module.ts in Angular 9, A cyclic dependency error occurs when using the code generated by openapi-generator-cli and a custom interceptor in the core app. Removing my interceptor causes the cyclic dependency issue to go away.
I'm not sure how the angular generator should be refactored to resolve this, or if a change of configuration might resolve the issue. I will start by matching your versions though because I could see this being an RX version issue.

@Nirostar
Copy link

Is this just as simple as updating the generator to reference Typescript >= 3.6.4 and rxjs? Or is more required? If it's that simple I can submit a PR for this issue as I'm keen to get it resolved also.

EDIT: Seems like its more than just that, I don't think the openapi generators work with AOT.

App startup asplodes with inject() must be called from an injection context

I have the exact same problem. Did you already fix it?

@macjohnny
Copy link
Member

@Nirostar if the current snapshot version still faces a problem, would you like to figure out which further changes need to be made apart from #5370?

@Nirostar
Copy link

everything works fine now. The inject() must be called from an injection context error was related to linking the package locally and was resolved by adding /projects/leaderportal-frontend-angular/architect/build/options/preserveSymlinks: true property to the angular.json of the consuming project.

See also: angular/angular#25813

@falk-stefan
Copy link

falk-stefan commented Jan 13, 2021

Somehow this is not working for me in a generated library of mine. Heres my angular.json excerpt:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "mobile-client": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "preserveSymlinks": true,

Any ideas?

Note: This is in Angular 11

See also: Question on stackoverflow

@3LexW
Copy link

3LexW commented Aug 11, 2022

Thanks for sharing the versions you are using. I will try going to rx 6.5.0+ and see if that improves anything.

My issue seems to be around importing HTTP_INTERCEPTORS into app.module.ts in Angular 9, A cyclic dependency error occurs when using the code generated by openapi-generator-cli and a custom interceptor in the core app. Removing my interceptor causes the cyclic dependency issue to go away. I'm not sure how the angular generator should be refactored to resolve this, or if a change of configuration might resolve the issue. I will start by matching your versions though because I could see this being an RX version issue.

@ltomes
Hi, sorry for mentioning this issue after a long while. I am facing the same issue when implementing customHTTP_INTERCEPTOR, and I would like to see if you can provide any solution to use it since this is the only relevant case I found.

@ltomes
Copy link

ltomes commented Aug 11, 2022

Thanks for sharing the versions you are using. I will try going to rx 6.5.0+ and see if that improves anything.
My issue seems to be around importing HTTP_INTERCEPTORS into app.module.ts in Angular 9, A cyclic dependency error occurs when using the code generated by openapi-generator-cli and a custom interceptor in the core app. Removing my interceptor causes the cyclic dependency issue to go away. I'm not sure how the angular generator should be refactored to resolve this, or if a change of configuration might resolve the issue. I will start by matching your versions though because I could see this being an RX version issue.

@ltomes Hi, sorry for mentioning this issue after a long while. I am facing the same issue when implementing customHTTP_INTERCEPTOR, and I would like to see if you can provide any solution to use it since this is the only relevant case I found.

Unfortunately I don't have access to this codebase anymore and I don't remember what the solution was. I do remember this was painful, and required the rest of the angular app to run on versions openapi-generator preferred.

@3LexW
Copy link

3LexW commented Aug 11, 2022

Thanks for sharing the versions you are using. I will try going to rx 6.5.0+ and see if that improves anything.
My issue seems to be around importing HTTP_INTERCEPTORS into app.module.ts in Angular 9, A cyclic dependency error occurs when using the code generated by openapi-generator-cli and a custom interceptor in the core app. Removing my interceptor causes the cyclic dependency issue to go away. I'm not sure how the angular generator should be refactored to resolve this, or if a change of configuration might resolve the issue. I will start by matching your versions though because I could see this being an RX version issue.

@ltomes Hi, sorry for mentioning this issue after a long while. I am facing the same issue when implementing customHTTP_INTERCEPTOR, and I would like to see if you can provide any solution to use it since this is the only relevant case I found.

Unfortunately I don't have access to this codebase anymore and I don't remember what the solution was. I do remember this was painful, and required the rest of the angular app to run on versions openapi-generator preferred.

I am currently working on Angular v14 right now and I think the openapi-generator is currently not supporting it, could this be a potential issue?

@macjohnny
Copy link
Member

@3LexW #12901

however, you can use the generated code even with angular 14 if you dont need the package.json

@3LexW
Copy link

3LexW commented Aug 12, 2022

@macjohnny
Hi, thank you for your reply, and yes I am currently using the plugin in Jetbrains IDEA to generate the code for Angular 14.

Since #12901 is still working right now, I don't know if the HTTP_INTERCEPTOR issue exists for v14 since it is not officially supported yet. Maybe I should convert my Angular version to v13 as the solution mentioned previously?

@macjohnny
Copy link
Member

@3LexW the differences in the generated code between ng 14 and ng 13 only affect the package.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants