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] OpenApi Generated ApiModule doesn’t register when declared in node_modules but works outside that folder

See original GitHub issue

Asked on stackoverflow too https://stackoverflow.com/questions/70700113/in-angualr-why-openapi-generated-apimodule-doesn-t-register-when-declared-in-nod

Description

I’m having an issue. I need to consume OpenApi Generated files (services, interfaces) via NPM package. The problem it doesn’t work when it’s in node_modules, but if I move it outside this folder it works. ApiModule comes as undefined when in node_modules for some reason. Github link in the bottom is documentation how to use it.

I have tried this on 2 different machines running Angular 12 (Node.js v12 and v16) with:

If I put in a different folder than node_modules it works, inside it doesn’t. Any help or ideas? Thanks.

Generation Details
app.module.ts:30 Uncaught TypeError: Cannot read properties of undefined (reading 'forRoot')
    at Module.6747 (app.module.ts:30)
    at __webpack_require__ (bootstrap:19)
    at Module.4431 (environment.ts:16)
    at __webpack_require__ (bootstrap:19)
    at __webpack_exec__ (log$:23)
    at log$:23
    at Function.__webpack_require__.O (chunk loaded:23)
    at log$:23
    at webpackJsonpCallback (jsonp chunk loading:33)
    at main.js:1
Steps to reproduce

Download either

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';

////// added
import { HttpClientModule } from '@angular/common/http';
import {
  ApiModule,
  Configuration,
  ConfigurationParameters,
} from 'client-petstore';


export function apiConfigFactory(): Configuration {
  const params: ConfigurationParameters = {
    basePath: 'https://localhost:4200',
  };
  return new Configuration(params);
}
////// end

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    ////// added
    ApiModule.forRoot(apiConfigFactory),
    HttpClientModule
    ////// end
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

7reactions
localrivetcommented, Jan 23, 2022

Any update on this?

from my end? no, I hit dead end before posting over here and nobody has pointed any mistakes in my process yet. I did see swagger-api/swagger-codegen#10908 (comment) but nothing came out of it too

@githubLurk

I ran into this same issue today and this link help me solve it. https://github.com/angular/angular-cli/issues/20987

After executing openapi-generator generate -g typescript-angular -i my-swagger-generated.json -o ./outdir I wasn’t running npm run build.

After running npm run build from the same ./outdir a new directory is created called ./dist.

From inside the ./dist directory I executed my npm publish and that solved my issue.

Hope this helps.

2reactions
githubLurkcommented, Jan 20, 2022

Any update on this?

from my end? no, I hit dead end before posting over here and nobody has pointed any mistakes in my process yet. I did see https://github.com/swagger-api/swagger-codegen/issues/10908#issue-806851648 but nothing came out of it too

Read more comments on GitHub >

github_iconTop Results From Across the Web

In Angualr why OpenApi Generated ApiModule doesn't ...
In Angualr why OpenApi Generated ApiModule doesn't register when declared in node_modules but works outside that folder? ; from '@angular/core' ...
Read more >
OpenAPI Definition & Online Tools | Open API Standards List
Engineers building APIs can use APIs to plan and design servers, generate code, and implement contract testing. Other internal teams can aggregate these...
Read more >
How I use an OpenAPI spec in my Angular projects
If you are working on a project that has an OpenAPI spec, ... In a few steps we can generate Angular specific code...
Read more >
Redocly tutorial -- authoring and publishing API docs with ...
Redocly provides a variety of tools for working with API docs. ... The CLI asks, “The following folders will be created: openapi and...
Read more >
VS Code API | Visual Studio Code Extension API
First register a command handler with the identifier extension. ... methods for common error-cases, like FileNotFound when a file or folder doesn't exist, ......
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