I'm encountering an error while trying to build my Ag-Grid using npm run build, can someone help me figure out

Being relatively new to Next.js and web development in general, my background mainly consists of working with compiled languages. I recently embarked on a project to build a web app using Ag-Grid, drawing inspiration from an example I found on a public GitHub repository that I managed to successfully set up and run: https://github.com/zealousAnemone/ag-grid-next-app/blob/main/pages/index.js

However, despite making some adjustments to the code (such as importing router from next/navigation and changing the location of ag-grid CSS imports), my npm run build command continues to fail.

`'use client'
import { useState, useEffect, useCallback, useRef } from 'react';
import { useRouter } from 'next/navigation';
import { AgGridReact } from 'ag-grid-react';

import 'ag-grid-community/styles/ag-grid.css';
import 'ag-grid-community/styles/ag-theme-alpine.css';

const Home = () => {
  const gridRef = useRef();
  const router = useRouter();
  const [rowData, setRowData] = useState([]);

  useEffect(() => {
    fetch('../api/staff')
      .then((response) => response.json())
      .then((data) => setRowData(data.rows));
  }, []);

  const onSelectionChanged = useCallback(() => {
  }, []);

  const defaultColDef = {
    resizable: true,
    sortable: true,
  };

  const [columnDefs] = useState([
    { headerName: 'First Name', field: 'first_name' },
    { headerName: 'Last Name', field: 'last_name' },
    { headerName: 'Job Title', field: 'job_title' },
    { field: 'office' },
    { field: 'email' },
    { field: 'phone' },
  ]);

  return (
    <div className="ag-theme-alpine" style={{ height: '600px' }}>
      <AgGridReact
        id="staff_grid"
        ref={gridRef}
        rowData={rowData}
        defaultColDef={defaultColDef}
        columnDefs={columnDefs}
        onSelectionChanged={onSelectionChanged}
        rowSelection={'single'}
        style={{ height: '100%', width: '100%' }}
      ></AgGridReact>
    </div>
  );
};

export default Home;`

The error generated during the build process is as follows:

./app/dashboard/AgGrid/page.tsx:39:7
Type error: No overload matches this call.
  Overload 2 of 2, '(props: AgGridReactProps<never> | AgReactUiProps<never>, context: any): AgGridReact<never>', gave the following error.
    Type 'MutableRefObject<undefined>' is not assignable to type 'LegacyRef<AgGridReact<never>> | undefined'.
  Overload 2 of 2, '(props: AgGridReactProps<never> | AgReactUiProps<never>, context: any): AgGridReact<never>', gave the following error.
    Type '({ headerName: string; field: string; } | { field: string; headerName?: undefined; })[]' is not assignable to type '(ColDef<never, any> | ColGroupDef<never>)[]'.

  37 |   return (
  38 |     <div className="ag-theme-alpine" style={{ height: '600px' }}>
> 39 |       <AgGridReact
     |       ^
  40 |         id="staff_grid"
  41 |         ref={gridRef}
  42 |         rowData={rowData}

Answer №1

Question :

Why am I encountering an error while trying to build my Ag-Grid using npm run build?

Potential issue :

const gridRef = useRef();

Possible Resolutions :

  1. const gridRef = useRef(null);
  2. Since your code is in TypeScript, they expect you to include an interface. Take a look at this example here Generic Type Example

Further Reading :

If you have any questions, feel free to leave a comment (I will update the answer as needed)

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

Mastering Typescript lookup types - effectively limit the properties included in a merge operation with the Partial type

Exploring lookup types, I'm interested in creating a safe-merge utility function that can update an entity of type T with a subset of keys from another object. The objective is to leverage the TypeScript compiler to catch any misspelled properties or ...

What is the reason behind receiving a 401 unauthorized error during the login process?

Currently, I am utilizing the NextAuth.js credentials provider for managing the login process. While attempting to log in, I have implemented error handling using a try-catch block to set the appropriate error state; however, I haven't incorporated di ...

I'm having trouble figuring out how to access response headers with HttpClient in Angular 5. Can anyone

I recently developed an authentication service in Angular 5, where I utilize the HttpClient class to make a POST request to my backend server. The backend server then responds with a JWT bearer token. Here is a snippet of how my request looks: return thi ...

Create a Jest mock for a namespace and a function that have the same name

The structure of a library I'm currently using is as follows: declare namespace foo { function bar(); }; declare namespace foo.bar { function baz(); }; My task involves mocking the functions foo.bar() and foo.bar.baz(). To mock foo.bar(), ...

Angular 6: Issues with API Get Method not executing when an integer value is passed with an empty string

I'm experiencing an issue in my angular application when trying to call an API method from angular. The method requires two parameters - one integer value and one string value, which is optional. Below is the code snippet in Typescript: let id:numbe ...

Tips for obtaining a subset of `keyof T` where the value, T[K], refers to callable functions in Typescript

Is there a way to filter keyof T based on the type of T[keyof T]? This is how it should function: type KeyOfType<T, U> = ... KeyOfType<{a: 1, b: '', c: 0, d: () => 1}, number> === 'a' | 'c' KeyOfType<{a: ...

Using Typescript: Utilizing generic types within the parent class

I'm currently facing an issue with the code snippet below, which is a simplified example: class QueryArgs { studentId?: string; teacherId?: string; } class BaseValidator<T> { protected args: T; constructor(args: T) { this.args = a ...

The attribute 'modify, adjust, define' is not found in the 'Observable<{}>' type

After attempting to follow a tutorial on Angular + Firebase, I encountered some issues with version compatibility. The tutorial was based on Angular 4, but my current version is Angular 6. Additionally, the versions of Firebase and AngularFire2 that I am u ...

Converting an array into an object by using a shared property in each element of the array as the key

I have an item that looks like this: const obj = [ { link: "/home", title: "Home1" }, { link: "/about", title: "About2" }, { link: "/contact", title: "Contact1" } ] as const and I want to p ...

No pathways can be established within Core UI Angular

I've been attempting to use the router link attribute to redirect to a new page, but instead of landing on the expected page, I keep getting redirected to the dashboard. Below is an overview of how my project's structure looks: [![enter image de ...

Troubleshooting WebSocket issues while utilizing Apollo Server with subscriptions within next.js API routes

Currently, I am in the process of setting up GraphQL Subscriptions within a next.js 9.x application. This app is purely for experimentation purposes to test Apollo Server subscriptions. Instead of a real database, I am using an array where new users are ad ...

Analyzing past UTC date times results in a peculiar shift in time zones

When I receive various times in UTC from a REST application, I encounter different results. Examples include 2999-01-30T23:00:00.000Z and 1699-12-30T23:00:00.000Z. To display these times on the front end, I use new Date(date) in JavaScript to convert the ...

Dealing with Typescript (at-loader) compilation issues within a WebPack environment

Currently, I am using Visual Studio 2017 for writing an Angular SPA, but I rely on WebPack to run it. The current setup involves VS building the Typescript into JS, which is then utilized by WebPack to create the build artifact. However, I am looking to t ...

Step-by-step guide on redirecting to a different page in NextJS if a dynamic route cannot be found

I need assistance with redirecting users when they access a dynamic route that does not exist. The dynamic route points to a field within a statically defined array of fields. Here is the code snippet for the page: import { fields } from "@/data/fiel ...

Discovering the right category for a general component: A step-by-step guide

How about creating a new list component that can work with an array of objects? <script setup lang="ts"> const props = defineProps<{ items: Record<string, unknown>[], selected: Record<string, unknown> | null field: stri ...

What factors may be influencing the incorrect behavior of this simple code when using useState()?

In an attempt to replicate a problem I encountered in a larger project component, I have created a simple component. Let's consider the scenario where we have an arrayA and we want to add the value 1 to it on each button click, while also updating ano ...

What is the proper way to declare the "any" module in TypeScript?

I am currently in the process of migrating a large project from JavaScript to TypeScript, taking it step by step. So far, I have converted one of the files to TypeScript, but the other files can contain any content at the moment. For example, something l ...

The AuthGuard (Guard decorator) is unable to resolve its dependencies according to Nest

My AuthGuard is responsible for checking the JWT token in controllers. I am trying to use this Guard in controllers to verify authentication, but I encountered the following error: Nest cannot resolve dependencies of the AuthGuard (?, +). Please ensur ...

Establishing a default value for Image src within next.js would ensure that a placeholder image

I have been struggling to set a default value for the image src in the Image component within my next.js project. I have not been able to find any options to handle the scenario where the server responds with a status code of 400. Currently, I am receiving ...

`Is there a way to assign multiple parameters to HttpParams within Angular 5?`

I'm attempting to send multiple parameters to HttpParams in Angular 5 using the approach below: paramsObject: any params = new HttpParams(); for (let key in paramsObject) { params.set(key, paramsObj ...