In Angualr why OpenApi Generated ApiModule doesn’t register when declared in node_modules but works outside that folder?

Viewed 519

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.

The project builds, it detects the files in path but on launching website I get error:

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

AppModule:

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 { }

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.

0 Answers
Related