The integration of ag-grid webpack css is not reflecting on the website as intended

I'm facing an issue with ag-grid in my react application where I can't seem to get the CSS working properly with webpack.

The grid is currently displaying like this:

image: https://i.sstatic.net/RPKvH.png

const path = require("path");
var webpack = require("webpack");
let HtmlWebpackPlugin = require("html-webpack-plugin");
let CopyWebpackPlugin = require("copy-webpack-plugin");
var BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
  .BundleAnalyzerPlugin;
var BitBarWebpackProgressPlugin = require("bitbar-webpack-progress-plugin");
let plug = require("@babel/plugin-proposal-class-properties");
module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      },
      {
        test: /\.(png|woff|woff2|eot|ttf|svg)$/,
        loader: "url-loader?limit=100000"
      },
      {
        test: /\.css$/,
        use: "css-loader/locals"
      }
    ]
  },
  node: {
    fs: "empty"
  },
  context: path.join(__dirname, "Scripts", "src"),
  entry: {
    d1: "./entries/d1Page.js",
    h1: "./entries/h1Page.js",
    polyfills: "./entries/polyfills.js",
    d2: "./entries/d2Page.js"
  },
  output: {
    path: path.join(__dirname, "Scripts/dist"),
    filename: "[name].bundle.js",
    publicPath: "/Scripts/dist/"
  },
  resolve: {
    extensions: [".json", ".js", ".jsx", "css"]
  },
  devtool: "source-map",
  plugins: [new BitBarWebpackProgressPlugin()],
  mode: "development"
};

When it comes to importing the CSS into my components, I'm doing it as follows:

import 'ag-grid-community/dist/styles/ag-grid.css';
import 'ag-grid-community/dist/styles/ag-theme-material.css';
import { AgGridReact } from "ag-grid-react";
.
.
.

Here's a snippet of my packages.json file:

"@babel/core": "^7.1.6",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/preset-env": "^7.1.6",
"@babel/preset-react": "^7.0.0",
"@material-ui/core": "^3.9.2",
"@material-ui/icons": "^3.0.2",
"babel-loader": "^8.0.4",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"bitbar-webpack-progress-plugin": "^1.0.0",
"copy-webpack-plugin": "^4.6.0",
"css-loader": "^1.0.1",
"es6": "0.0.7",
"es6-promise": "^4.2.5",
"fs": "0.0.1-security",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.26.0",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10",
"whatwg-fetch": "^3.0.0",
"ag-grid-community": "^20.2.0",
"ag-grid-react": "^20.2.0"

I've tried various loaders and resolvers as recommended by ag-grid but haven't had any success so far. Any insights on what might be causing this issue?

Answer №1


Make sure to carefully examine the file paths and file names when encountering import issues. Verify that your current import method is accurate.

Consider trying:

@import url('../node_modules/ag-grid/dist/styles/ag-grid.css');
@import url('../node_modules/ag-grid/dist/styles/ag-theme-fresh.css');

Additionally, add the following to .angular-cli.json:

"styles": [
    "../node_modules/ag-grid/dist/styles/ag-grid.css",
    "../node_modules/ag-grid/dist/styles/theme-fresh.css"
],

Ensure to use your specific path for imports and styles.

Experiment with changing .css to .scss in your imports.


If issues persist, check the browser console or project terminal for potential errors.

Don't forget to consult the documentation as well: https://www.ag-grid.com/react-getting-started/


For a visual demonstration, visit this GitHub repository: https://github.com/ag-grid/ag-grid-angular-example


Hope these suggestions prove helpful!

Sincerely, Brhaka

Answer №2

It seems from your import statements for the Ag-Grid CSS files and the Ag-Grid documentation for React, that you may be missing a resolution alias configuration for the ag-grid-community directory within your node_modules.

To resolve this, consider adding the following to your Webpack configuration:

resolve: {
    alias: {
        "ag-grid-community": path.resolve('./node_modules/ag-grid-community')
    }
},

You may also need to review your CSS loader setup in the Webpack configuration. Check out some example configurations available in the ag-grid-react-example repository on GitHub:

Based on these sample Webpack configurations, the CSS loader is typically set up as shown below:

module: {
    rules: [
        {
            test: /\.css$/,
            loader: "style-loader!css-loader"
        },

We hope this information proves helpful!

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

What are the steps to create an endless scrolling feature?

I'm trying to create a slider with a horizontal scrolling effect, but I've hit a roadblock. How can I make the slider scroll infinitely? In my code, you can see that after Item 6, it stops scrolling and I have to scroll backward. However, I want ...

Acquire a JPG file from IPFS utilizing the Infura API and ipfs-http-client in a React project

Using the infura API and ipfs-http-client, I successfully uploaded a jpg image onto IPFS. The file was selected through an input with type=file, triggering the onchange event listener. // necessary imports const IpfsHttpClient = require("ipfs-http-cli ...

Developing a barrel component in React (utilizing .tsx)

My current directory structure looks like this: src assets components models counter.tsx index.ts The code found inside models/index.ts (also known as the barrel file) export * from "./counter"; The code within models/counter.ts export default in ...

Dealing with Cross-Origin Resource Sharing problem in a React, TypeScript, Vite application with my .NET backend

I'm encountering a CORS issue when trying to make a Request using Fetch and Axios in my application hosted on the IIS Server. Here are my Server API settings: <httpProtocol> <customHeaders> <add name="Access-Control-Allow-O ...

The substance (singular word) extends beyond the margins of the mobile screen

I am facing an issue on my webpage where the title is too long and it goes out of the page on mobile devices. Here is an example: <div class="module-head"><h3 class="module-head-title">Search Engine Optimization - Why Is It ...

Interacting with a dynamically generated component in React triggers the render method upon hovering over it

One of the features in my application is a Google Map that displays markers based on coordinates retrieved from an API. When the app loads, it makes an API request to fetch a few coordinates to show on the map. The API data is then used to map to a <Mar ...

Creating sequential numbers using jQuery

Recently, I worked on a script (credit to Chyno Deluxe) that generates a list of menu items based on what is written in the input box. However, I now have a new requirement which involves generating a sequence of numbers to be added continuously. Here is ...

Is there a way I can appropriately display an image in a specific size box?

Check out the code snippet I wrote below: import React from 'react' function OurCourse() { return ( <div className='w-full '> <div className='w-full h-[390px]' style={{ backgroundImage:&apos ...

The performance of the frontend application is severely degraded due to a bottleneck in Graphql nested queries when using Django and React. Assistance in resolving this issue would be greatly

My current project involves using Python+Django and GraphQL (graphene) for the backend, MySQL as the database, and React.js for the frontend. Once a user logs in on the frontend, the following query needs to be executed: const GET_ORGANIZATION = gql` quer ...

"Creating Rounded Corners in HTML: A Step-by-Step Guide

Is there a way to round the corners of this image? Below is an excerpt from my body... <body> <h1 style="float:left; width:37%;"><font color="#99CC00"><font face="Verdana">MrEpicGaming4U</font></h1> <div style= ...

Establish the dimensions of the element to match the dimensions of a responsive image

Currently, I am working on implementing flippable images on my website. It is important to me that the "back" of these images matches the dimensions of the front image. The challenge I am facing is that I have applied the Bootstrap img-responsive class to ...

Issues with the background color of the bootstrap 'card' when implementing a QR code

How can I customize the background color for a Bootstrap card, specifically filling the entire card including the card text section? <div class="content"> <div class="card"> <img src="images/qr-code.png&q ...

The :after pseudo-element in action with multi-line text

Can the styling of the :after pseudo-element be applied to every line of multi-line text? Here is the code I am currently using: .container { width: 50px; } .text { position: relative; } .text:after { content: ''; position: ...

Every time I attempt to launch the React boilerplate on localhost, I encounter an error

For more information, please visit: https://github.com/react-boilerplate/react-boilerplate I followed the instructions to run the project on localhost, but encountered the following error. Can anyone assist me with this? npm ERR! code 1 npm ERR! path C:& ...

Adding a Click class can cause significant disruption to the entire CSS layout

I am facing an issue with transforming the X position and appending an additional class to create a slide effect in React. It seems to be working differently compared to using vanilla JavaScript. Below is the code snippet: .inputModal { position: absolut ...

The function within the React component is failing to produce the expected output

After importing two types of images (IMG and IMG2), I wanted to display IMG when the viewport width is less than 600px, and IMG2 when it's equal to or greater than 600px. I created a function to determine the viewport width and return the respective i ...

Unpredictable preset inline styles for HTML input elements

While developing a full-stack MERN application, I encountered an unusual issue when inspecting my React UI in Chrome DevTools. If any of these dependencies are playing a role, below are the ones installed that might be contributing to this problem: Tail ...

After integrating redux and setting up private/public routing, the component will not be re-rendered by the `<Link>` element

An update has been made: A demo has been uploaded on CodePen. You can find it here I am currently using a Drawer from the material-ui CSS library, specifically for an admin control panel. The Drawer consists of the AppRouter component. When I navigate thr ...

Change the CSS dynamically

I'm curious about how to create a similar effect like the one on this page: On the left side, there is a panel that allows for adjusting the template. What I've noticed is that when I change the color, different CSS files are used (blue.css, pur ...

Ways to turn off caching in Redux toolkit query?

In the situation I am facing, there are two queries that I am working with: getAllPosts and getPost. Whenever the getPost query is executed, it triggers an update to the query data of getAllPosts using the queryDataUpdate method. However, each time getPo ...