Why does the OpenApi Generated ApiModule in Angular fail to register when declared in the node_modules directory but functions properly when placed outside that folder?

Encountering a problem with consuming OpenApi Generated files (services, interfaces) via NPM package. Strangely, it works outside the node_modules folder but ApiModule is undefined when placed within. Refer to the Github link below for documentation on usage.

While the project builds successfully and detects the files in the path, an error occurs upon website launch:

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

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

The issue seems to be related to the folder placement – it works outside node_modules but not inside. Any suggestions or assistance would be greatly appreciated. Thank you.

Answer №1

Encountered a similar issue when I tried to publish my module using npm publish instead of npm publish dist/. It's important to specify the generated folder when publishing the packages!

To test this, I created a sample package - mysample-test-package.

  1. Released version 1.0.0 without specifying the folder and faced issues
  2. Released version 1.0.2 by specifying the dist folder, which worked perfectly

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging a Derived-Class Object Within the Base-Class to Invoke a Base-Class Function with Derived-Class Information

I have a situation where I need to access a method from a derived class in my base generic component that returns data specific to the derived class. The first issue I encountered is that I am unable to define the method as static in the abstract class! ...

Deploying Firebase functions results in an error

Just recently started exploring Firebase functions. Managed to install it on my computer, but running into an error when trying to execute: === Deploying to 'app'... i deploying firestore, functions Running command: npm --prefix "$RESOURCE_ ...

Is there a way to make sure video files are downloaded instead of automatically playing in the browser window?

I have a link to a video file with various formats like mp4, 3gp, etc. When I click on the link, it opens in the same tab. Changing the target attribute to "_blank" makes the video open in a new tab. However, when I ctrl-click the link, the file s ...

The Nest Scheduler - Cron decorator may encounter missing dependencies when used in conjunction with another decorator by applying multiple decorators

In my current project, I am developing a custom cron decorator that not only schedules tasks but also logs the name of the task when it is executed. To accomplish this, I have merged the default nestjs scheduling Cron decorator with a unique LogTask decora ...

Guidelines for dynamically displaying <router-link> or <a> in Vue based on whether the link is internal or external

<template> <component :is="type === 'internal' ? 'router-link' : 'a'" :to="type === 'internal' ? link : null" :href="type !== 'internal' ? link : null" > <slot /> < ...

Techniques for concealing a button when the "disabled" attribute is set to "true"

The button is currently disabled, however, I intended for it to be hidden from the UI when the disabled condition is met - <button ion-button block class="button-color-blue" [disabled]="true" (click)="closePage()"> Cancel </b ...

Investigating TypeScript Bugs in Visual Studio Code

As I navigate through various sources, I notice that there is a plethora of information available on older versions of VSCode (v1.16.1 - the most recent version at the time of writing) or deprecated attributes in the launch.json file. I have experimented ...

Angular - Executing a function in one component from another

Within my Angular-12 application, I have implemented two components: employee-detail and employee-edit. In the employee-detail.component.ts file: profileTemplate: boolean = false; contactTemplate: boolean = false; profileFunction() { this.profileTempla ...

Module 'commander' not found

Whenever I attempt to execute my mocha tests, I encounter the following error: $ npm t > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="35515c525c415459745954475876595a565e75041b051b05">[email protected]</a> ...

Typegoose and NestJS: The 'save' property is not found on this type

I recently started using typegoose and nestjs for my backend-server. In my pages.service.ts file, I already have a function called getPageById() to retrieve a single page by its ID. However, when trying to call this function from another function within th ...

Why is TS1005 triggered for Redux Action Interface with an expectation of '=>'?

I'm finding it difficult to identify what's causing this issue, as shown in the esLint error from Typescript displayed in the screenshot below: https://i.stack.imgur.com/pPZa7.png Below is the complete code, which consists of actions for redux. ...

How can I prevent the enter key from working with Twitter Typeahead?

Is there a way to prevent the enter key from being pressed on an element within Twitter Typeahead's dropdown feature while using Angular with Typescript? I attempted to utilize preventDefault() when event.keycode === 13 on the ng-keydown event for th ...

Error in Vuepress: Attempting to read properties that are not defined (specifically 'match')

I encountered an error while attempting to build my vuepress project. I followed this npm quickstart guide: After adding some pages, everything was functioning correctly with: npm run:dev However, when I tried to generate html to docs/src/.vuepress using ...

Is there a way in typescript to transform empty strings into null values?

As a newcomer to TypeScript, I have been exploring it for some time now. I am working with two interfaces, one is fetching data from a database that I do not have control over and cannot guarantee the values returned are as expected. // Retrieved from the ...

Using wildcard in Angular app for MQTT observation

My curiosity lies in MQTT wildcards and how they function, specifically while utilizing the mosqitto broker. Let's say I have around 1-2k topics. In my frontend, I am observing them with a single-level wildcard using ngx-mqtt. Will there be a separat ...

Can someone assist me with updating the Node version on my Mac so I can utilize Next JS? I am encountering an error despite having it installed

So I've decided to start a new NextJS App, but it seems like it needs a Node version higher than v18.17.0 to run properly with Next JS. I've been attempting to update it, but for some reason, the active node version doesn't match the one I w ...

The addControl function inside a for loop and async function is not properly assigning a value to the form

My goal is to iterate through an array, make a HTTP request, retrieve another array from it, and assign the selected object from the fetched array to a newly added Form Control in the form. This is how I approached it: for (let i = 0; i < typeaheadFiel ...

Angular 5 - Implementing "similar to %" Filter (similar to SQL)

I have created a method in my code to filter an array based on a specific type. filterByType(type: string) { console.log("Filtering by type"); this.filteredArray = null; this.filteredArray = this.mainArray.filter((item: Item) => item.type === type); t ...

Tips for Sending Variables in HTTP Requests in Angular 9

'''Is there a way to pass fromDateTime and toDateTime as parameters in this link?''' export function MSALInterceptorConfigFactory(): MsalInterceptorConfiguration { const protectedResourceMap = new Map<string, Array& ...

The Expo TypeScript template highlights JSX errors such as "Cannot assign type 'boolean' to type 'View'. TypeScript error 2322 at line 5:10:5"

Just starting out with Expo and decided to dive in with the typescript template using the npx create-expo-app -t expo-template-blank-typescript command. However, I'm running into some JSX type errors that are popping up even though the Expo server see ...