Encountering Maximum Call Stack Size Error When Integrating PrimeNg Table Module into Component

I recently encountered an issue with my Angular component npm package when I tried to incorporate a p-table into my HTML. The problem seems to be originating from the components module file.

Adding the primeNg tableModule to my app.module file works fine, but as soon as I include it in the components module file and run "npm run packagr" to bundle my package, I encounter the following error:

Maximum call stack size exceeded

Below is an excerpt from my header.module file highlighting the lines causing the error:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HeaderComponent } from './header.component';
import { TableModule } from 'primeng/table'; //TABLE MODULE IS CAUSING THE ERROR

@NgModule({
  declarations: [HeaderComponent],
  imports: [CommonModule, TableModule], //TABLE MODULE IS CAUSING THE ERROR
  exports: [
    HeaderComponent,
  ],
})
export class HeaderModule {}

While searching for solutions to this error, most resources seem to focus on recursive loops, whereas in my case, simply adding the TableModule to the modules file triggers the error.

Could anyone shed light on why this specific inclusion is triggering the error?

UPDATE!!!

This is the p-table snippet present in my header.html file that's causing the trouble:

<p-table
    [columns]="this.templateRows"
    [value]="this.tableData"
    responsiveLayout="scroll"
    [scrollable]="true"
    scrollHeight="100px"
    [virtualScroll]="true"
  >
    <ng-template pTemplate="header" let-columns>
      <tr>
        <th *ngFor="let col of columns">
          {{ col.header }}<br />
          <small>{{ col.regex }}</small>
        </th>
      </tr>
    </ng-template>
    <ng-template pTemplate="body" let-rowData let-columns="columns">
      <tr>
        <td *ngFor="let col of columns">
          {{ rowData[col.header] }}
        </td>
      </tr>
    </ng-template>
  </p-table>

The following is the app.module where the tableModule import works without any issues:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HeaderModule } from './modules/header/header.module';
import { TableModule } from 'primeng/table';
@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, AppRoutingModule, HeaderModule, TableModule],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

Finally, here's a glimpse at the header.component.ts file:

import {
  Component,
  EventEmitter,
  OnInit,
  Input,
  Output,
  ViewChild,
  ElementRef,
} from '@angular/core';
import * as FileSaver from 'file-saver';
import * as XLSX from 'xlsx';

@Component({
  selector: 'app-header-naomi',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.css'],
})
export class HeaderComponent implements OnInit {
  @ViewChild('fileUpload', { static: false }) fileUpload: ElementRef;
  headerRow: any = [];
  tableData: any = [];
  templateRows = [
    { field: 'name', header: 'Name', regex: '[a-zA-Z]' },
    { field: 'age', header: 'Age', regex: '^[0-9]*$' },
    { field: 'year group', header: 'Year Group', regex: null },
  ];

  constructor() {}

  ngOnInit(): void {
  }
 
  processUpload() {
    const fileUpload = this.fileUpload.nativeElement;
    fileUpload.click();
  }

  async uploadFiles() {
    const fileUpload = this.fileUpload.nativeElement;
    this.tableData = this.validateSpreadsheet(fileUpload, this.templateRows);
  }

  async validateSpreadsheet(fileUpload: any, templateRows: any) {
    let uploadData: any = [];
    for (const file of fileUpload.files) {
      const fileExtension = file.name.split('.').pop();
      let valid = false;
      if (fileExtension === 'csv') {
        valid = true;
      }
      if (!valid) {
        throw "Unsupported file type, file must be 'of type .csv";
      }
      const reader = new FileReader();

      reader.onload = async (e: any) => {
        const data = new Uint8Array(e.target.result);

        const workbook = XLSX.read(data, {
          type: 'array',
          cellDates: true,
          dateNF: 'dd/mm/yyyy',
        });
        if (workbook.SheetNames.length === 0) {
          console.error('No sheets');
        }
        for (const sheetName of workbook.SheetNames) {
          const rows: any = XLSX.utils.sheet_to_json(
            workbook.Sheets[sheetName],
            {
              defval: null,
            }
          );

          for (let row of rows) {
            uploadData.push(row);
          }
        }
      };
      reader.readAsArrayBuffer(file);
      return uploadData;
    }
  }
}

Answer №1

I encountered an issue with this, but was able to resolve it by deleting the node modules and package-lock.json file. Afterwards, I reinstalled them.

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

Unique validator for form fields in Angular Reactive Forms when in edit mode

In my current project, I am developing an Angular 8 application using Reactive Forms. The form in question serves both create and update operations with a set of controls. Here is the code snippet for initializing the form: this.form = new FormGroup({ ...

Tips for encoding data to JSON format in Angular

I am unsure if I am sending the username and password in JSON format correctly. As a beginner in Angular, I want to make sure I am doing it right. myApp.controller('loginController',['$scope','$http', function($scope, $http) ...

Getting permission for geoLocation service on iOS in Ionic: A step-by-step guide

I have recently developed a social media application that utilizes geoLocation services. The app is built with Ionic 4 and has a Firebase backend. While the GeoLocation services are functioning properly on Android devices, users of iOS are not being prompt ...

When Electron's WebView.loadURL is called, it initiates a reloaded page

According to the documentation provided by Electron, it is necessary to wait until the webview element is available in order to utilize its respective methods. While most methods function properly, I am facing challenges in understanding how to programmati ...

Why Am I Getting a Method Not Allowed Error When Trying to Use POST with OAuth2?

I am currently in the process of developing a website that requires integration with the Discord API in order to access user information. In order to achieve this, I have been utilizing a library called Simple OAuth (https://github.com/lelylan/simple-oauth ...

Steps to open and configure a Mobile-Angular modal from another controller

Is it possible to use a modal in Angular JS for mobile devices without compromising the layout? I'm having trouble setting up the controller for my modal inside my main controller and passing parameters. Should I consider using ui-bootstrap for this p ...

Navigating through props outside a class component in React

I'm struggling to grasp how I can access props that are defined outside of a React class component. In the code snippet below, all props are clearly outlined except for this.props.checkboxArray, which is currently throwing an error "cannot read prope ...

Troubles with retrieving API search results using Vue computed properties

I've recently developed an Anime Search App using Vue.js and the new script setup. I'm currently struggling to access the search results in order to display the number of titles found. The app is fetching data from an external API, but it's ...

Using Typescript to create static methods on mongoose schemas

I am currently working on implementing a mongoose model with TypeScript. It's nothing too complex, just trying to get it up and running. The code I have compiles successfully, but with some warnings: import crypto = require('crypto') impor ...

Using jq and node.js to translate AWS EC2 tags

Seeking assistance with transforming this array of EC2 tags using jq and node.js: [ { Key: 'Name', Value: 'xxx' }, { Key: 'role', Value: 'yyy' } ] I want to transform it to: { name : 'xxx', ro ...

Issue with async waterfall not triggering the next callback function when combined with a promise

async.waterfall(eventIDs.map(function (eventId) { console.log(eventId); return function (lastItemResult, nextCallback) { if (!nextCallback) { nextCallback = lastItemResult; las ...

After removing an element from an array in Vue.js, how can we adjust its class to reflect the change?

Apologies for my lack of proficiency in English. I am eager to find a solution to resolve these issues. I am working on a todolist and encountering an issue where the class ('centerLine') continues to affect the next element after deleting an a ...

Want to learn how to integrate React-pdf (@react-pdf/renderer) with TypeScript on NodeJS and Express JS?

I am encountering difficulties running React-Pdf (@react-pdf/renderer) with TypeScript on an Express JS server. I have attempted to use babel but encountered errors that I cannot resolve. build error error error You can find the Github repository for t ...

provide an element reference as an argument to a directive

I am trying to figure out how to pass an element reference to a directive. I know that I can get the reference of the element where the directive is applied using private _elemRef: ElementRef but my goal is to pass the reference of another element to the ...

Interval function not initiating properly post bullet navigation activation

Currently, I am experiencing an issue with my custom slider where the auto sliding set interval function is not working after using the bullet navigation. Despite trying to implement "setTimeout(autoSlide, 1000);", it doesn't seem to be resolving the ...

Unable to retrieve the parent element using jQuery

I am facing an issue with my html structure that is generated dynamically through a foreach loop. I have attempted to remove the entire <a> element by accessing it from its ACTIVE HYPERLINK. However, all my efforts seem to be in vain as I am unable t ...

The LinkButton feature is not functioning correctly in combination with the showmodaldialog

What is the best way to open a window.showModalDialog with a link button when updating a form? I have a link button on my form that updates data. When the client's status becomes active, I want to open a window for additional information entry. Pub ...

Error Encountered: NPM - Application Framework Installation Issue

While attempting to set up the framework7 app from the app-framework GitHub, I encountered an error: npm WARN enoent ENOENT: no such file or directory, open '/Users/user/package.json' npm WARN user No description npm WARN user No repository fiel ...

An error has occurred: module not found at internal/modules/cjs/loader.js:969

When attempting to run my app, I encountered an unexpected error. Can anyone explain why this happened? This is the structure of my project: ./ ├─ app.js ├─ .env ├─ .gitignore ├─ node modules/ │ └─ ... ├─ package.json ├─ pac ...

The .prepend() method receives the variable returned by ajax and adds it

I'm facing a challenge with adding a dynamic select box to a string within my .prepend() function. The options in the select box are subject to change, so hard coding them is not an option. To tackle this issue, I am using an AJAX call to construct th ...