Issue with node modules conflicting with Global CSS in Next.js

Currently in the process of transitioning a project from create react app to nextjs and I've encountered an issue.

./node_modules/react-bootstrap-submenu/src/index.css
Global CSS files cannot be imported from within the node_modules directory.
Learn more: https://nextjs.org/docs/messages/css-npm
Location: node_modules\react-bootstrap-submenu\dist\DropdownSubmenu.js

Has anyone found a solution to this problem?

Answer №1

Check out this documentation

Starting from version 9.5.4 of Next.js, you can now import CSS files from node_modules anywhere in your application.

For global stylesheets such as bootstrap or nprogress, it is recommended to import the file within the pages/_app.js file. Here's an example:

// pages/_app.js
import 'bootstrap/dist/css/bootstrap.css'

export default function MyApp({ Component, pageProps }) {
  return <Component {...pageProps} />
}

If this method does not work for your specific situation, consider trying the following solutions.

  1. Copy the CSS file to public/static.
  2. Then, import the file like this:
// pages/_app.js
import 'public/static/bootstrap.css'

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

The transparency feature using rgba is not supported in the Chrome browser for Android

Have you noticed the transparency effect in certain divs using the rgba CSS property? Strangely, Chrome on my ASUS tablet and Samsung S3 mini Galaxy smartphone does not seem to support this feature. Surprisingly, Internet Explorer does! Any insights on w ...

Manipulate CSV column data using REACTJS

After receiving a CSV file with multiple columns from the backend, I have the need to make some modifications to one of the columns before exporting it as a report. Currently, I am utilizing the react-csv library for this export process. The specific colu ...

What is the best way to select both an inline element and a block-level element at the same time?

After receiving a shortcode from a WordPress theme, the output is: <div class="heading clearfix"><i class="icon icon-list-ol h2"></i> <h2> Hello World! </h2></div> I am looking to style both the icon and h2 elements to ...

Is there a way to prevent the window.status from appearing?

I currently have the following code snippet: <a class="button accessLink" id="loginLink" href="#" data-action="Login" data-dialog="access" data-disabled="false" data-entity="n/a" ...

Conceal the content within the body and reveal a uniquely crafted div element using Print CSS

I came across numerous resources on using CSS to hide specific parts of a webpage. However, I am not looking to hide multiple divs like this: #flash,#menu,#anuncios { display:none; } Instead, my goal is to hide the entire body of the page and only displ ...

Issues with testing incorporating jest, react, webpack, and SVG

I recently delved into the world of React development, but I've hit a snag when trying to run a test with an SVG file. You can find the code in my GitHub repository https://github.com/alejomongua/react-playground. Upon running npm run test, I encoun ...

I am puzzled about why my localhost client is not receiving a cookie back even though I am using express-session

I am encountering some challenges with node's express-session and I am attempting to gain a better understanding of how it interacts with cookies and my session store in my postgres database. Initially, I am puzzled as to why I am not seeing a sessio ...

Get rid of the lower padding on a handsontable

I am currently using either Chrome Version 61.0.3163.100 (Official Build) (64-bit) or Safari Version 11.0 (12604.1.38.1.7) on Mac OS Sierra 10.12.6. I am looking to create a handsontable that may exceed the screen height: Click here for an example As I ...

Issue with VS2010: CSS intellisense failing to display id or class names

Is it possible for intellisense to activate when typing a # or . in a CSS file, displaying a list of the class/id names? I currently receive intellisense within the curly brackets, but not for the classes and ids themselves. How can I achieve this functi ...

Can you provide guidance on implementing StyledComponents within the app folder of Next.js version 13?

Quoting information from the Next.js documentation: Attention: CSS-in-JS libraries that rely on runtime JavaScript are currently not compatible with Server Components. The following libraries are supported in Client Components within the app directory: s ...

Two child elements aligned vertically must adjust their heights to fill the entire height of the parent container, with both heights being dynamic

I am doubtful that this scenario can be achieved, but I am optimistic that someone will present a solution to prove me wrong. My parent element does not have a fixed height (though it could, although I don't believe it would help). Within this parent ...

CSS modified after opening a modal dialog that has loaded external HTML content

Within my ASP.NET MVC project, I am utilizing a tab wizard. On one of the tabs, I trigger a modal dialog by loading HTML content from an external API. However, once I close the wizard and navigate to the next tab, the table style (specifically border color ...

The process of enriching an ASP.NET hyperlink by making it both bold and under

I'm currently working on a webpage in asp.net. I have two hyperlinks and I want to make them active by applying a style sheet that makes them bolder and underlined, but for some reason it's not working. Here is the HTML: <li style="margin-le ...

Arrangement of divs on a stretched background

Seeking assistance to code a layout using div layers that resembles the design in this sample: The concept involves dividing the background into 4 distinct sections with content placed centrally. The upper part will feature a main banner image over pink a ...

Using Angular JS for Traditional Multi-page Websites

Lately, I've been diving into Angular 2 and I have to admit, it's an impressive framework for building single-page applications. But here's the thing - how would one go about integrating Angular with a traditional website (maybe using codei ...

What is the best way to get Nextjs?

I am struggling to update movie data from the API. It seems like the server only fetches the data once and does not fetch again when there is new data available. async function fetchAllMovies() { try { const fetchOptions = { headers: { ...

(Applied jQuery) Trouble with div height in responsive layout

I have created jQuery full-page sliding panels that work perfectly on desktop devices. However, when the browser window is resized smaller, the panel divs fail to fill the page. If you want to view the issue in action, you can check out the JSFiddle demo ...

What steps can I take to prevent encountering the error message 'Function components are not able to be given refs' while utilizing react-router-dom?

Here is the code snippet using Material UI components... import React from "react"; import { NavLink } from "react-router-dom"; import Tabs from "@material-ui/core/Tabs"; import Tab from "@material-ui/core/Tab"; function LinkTab(link){ return <Tab ...

The console output is repeated twice

Having an issue with Hooks Methods in React. I am working on an input search and when the key "Enter" is pressed, it triggers a function to set the value. However, I am encountering a problem where the console.log("hi") is being printed twice for some unkn ...

Capture any clicks that fall outside of the specified set

I am facing an issue with my navigation drop down menu. Currently, the pure CSS functionality requires users to click the link again to close the sub-menu. What I want is for the sub-menu to close whenever a click occurs outside of it. I attempted a solu ...