When using NextJs, running the commands 'npm build' and 'npm start' can sometimes cause style inconsistencies

Currently working on a project with NextJs (sorry, no screenshots allowed). Running 'npm run dev' for development works perfectly fine, but when I switch to 'npm run build' and then 'npm start', the website displays overlapping components, indicating a possible CSS issue. Any suggestions on what might be causing this? Appreciate your help!

Latest Update:

The mini-css-extract-plugin flagged conflicting ordering in my CSS imports as the potential root cause of the problem. Although identified, I'm still unsure how to resolve it.

Answer №1

Last week, I encountered a few CSS issues and stumbled upon the mini-css-extract-plugin. After reading an article recommending the use of CSS loaders, I decided to check if it would help by updating my next.config.js file. Initially, I added the mini-css-extract-plugin but later commented it out. Instead, I included these loaders: ['style-loader', 'css-loader', 'less-loader'] and organized all CSS in _app.js with proper SSR-based MaterialUI styling in _document.js.

const withImages = require('next-images')
module.exports = withImages()
// const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const withCSS = require('@zeit/next-css')
const withLess = require('@zeit/next-less')
const withSass = require("@zeit/next-sass");


module.exports = withImages({
   target: 'serverless',
   webpack: function (config, { webpack }) {
    config.module.rules.push({
        test: /\.(eot|svg|gif|md)$/,
        // use: 'raw-loader',
        // test: /\.(sass|less|css)$/,
        loaders: ['style-loader', 'css-loader', 'less-loader']
    })
    config.plugins.push(new webpack.DefinePlugin({
        'process.env': {
            NODE_ENV: JSON.stringify(process.env.NODE_ENV),
            ENV: JSON.stringify(process.env.ENV),
        }
    }))
    return config
   },
  })

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

Utilizing the Filter Function to Eliminate an Element from an Array

I am a beginner in the world of React and I'm currently working on developing a simple timesheet tool where users can add tasks and save them. My tech stack includes React and Typescript. Currently, my main component has an empty array for tasks and ...

Exploring ways to integrate Email.js CDN into Next.js framework

Struggling to find a clear solution on how to correctly import this. I have installed Email JS via NPM and attempted to import it using the HEAD tag. <Head> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ema ...

Error TS2339: The 'getOoxml' property is not found within the 'Worksheet' type

Running on node version 20.12.0 "react": "^18.2.0" I created a React application using the Yo Man generator for Office version 5.0.0. The code in the file looks like this: async function getExcelOOXML() { try { await Excel ...

What is the best way to apply fill to SVG using Tailwind CSS?

I tried using the code provided, but unfortunately, I was unable to Override the fill. The issue seems to have been resolved, but can someone help me achieve this using tailwind CSS? <div className=""> <svg className="text- ...

I am currently developing a program that is displaying a blank page despite my efforts to write

I've been trying to write the code below but it only shows a blank page. var greeting = React.createClass({ render: function() { return ( <div> <h1>Hello</h1> </div> ...

Struggling to resolve this npm installation issue post Windows 11 update - any suggestions?

After recently upgrading to Windows 11 and Visual Studio 2022, I encountered a series of errors during the npm install process when trying to install an app that was previously functional on Windows 10. This particular app serves as the UI for a website ...

Encountering problem on Heroku: Bower resolver is missing

Are you familiar with the concept of Javascript fatigue? I have recently become aware of it. Although I am not a javascript developer, I use Node and Angular for a side project on my server. All my node packages are installed using npm and my angular pa ...

My website experiencing issues due to Firefox 23.0.1 altering the CSS and causing disruptions

After setting up a test site for a client to review as part of a proof of concept, I noticed an unexpected white line while checking across different browsers. (loading correctly in all browsers except FF) In Firefox, there appears to be a thin ~10px li ...

Issue: Module 'ansi-styles' not found when using AngularJS and Yeoman generator

Previously my code was functioning perfectly, but now it seems to have suddenly stopped working. Attempting yo angular:route api resulted in the following error message: Error: Cannot find module 'ansi-styles' at Function.Module._resolveFilen ...

"Discover the secrets of flipping a webpage just like turning the pages of

I recently designed a basic website with 4 separate pages. The homepage includes navigation links for each page, such as - Page1 page2 Page3 Page4 My goal now is to create a feature where clicking on any of these links will open the corresponding page wi ...

Moving object sideways in 100px intervals

I'm struggling to solve this issue. Currently, I have multiple div elements (each containing some content) that I need to drag and drop horizontally. However, I specifically want them to move in increments of 100px (meaning the left position should b ...

We are in need of a provider for the Ionic Network native plugin

I have encountered an issue while trying to use Ionics native plugin "Network" as it fails due to a missing provider. To prevent any errors, I performed a fresh installation of Ionic along with the necessary dependencies: ionic cordova plugin add cordova- ...

I'm facing the challenge of trying to work on an Angular project without access to the node_modules folder, and unfortunately, I

Error report regarding npm resolution While resolving: [email protected] Found: @angular/[email protected] node_modules/@angular/common @angular/common@"^14.2.12" from the root project Could not resolve dependency: peer @angular/commo ...

Troubleshooting issue with applying hover effect to child divs

How come when I hover over one of the child items in my parentDiv, the background of the last childDiv changes no matter which child I place my mouse on? for (let i = 0; i < Number(height); i++) { for (let j = 0; j < Number(width); j++ ...

Is it allowed to rewrite the JavaScript codes after detaching the app from Expo?

For my Android app, I need to incorporate a gif which may require detaching my expo project. I'm unsure if detaching my expo project using expoKit will allow me to continue writing code in JavaScript as usual. Detaching creates separate folders for A ...

Stopping Accordion Title from Moving Vertically in Material-UI

Just finished creating this accordion which will be used as a menu item. However, I've encountered an issue where clicking on the Main title causes the accordion summary to move downward vertically. Any suggestions on how to keep the Main tile fixed ...

Comparing Next.js - dynamic imports versus using the await import statement

I am curious about the contrast between dynamic import (a feature of next.js) and await import. I conducted a search online but couldn't find any explanation about this difference. From what I gathered, it seems that dynamic import is used specificall ...

I'm sorry, but you can't use objects as a React child (found: [object Promise]). If you intended to display a group of children, make sure to use an array instead. What

I followed a tutorial on YouTube to replicate something for my application. It worked in the tutorial, but now I'm facing an error. The data is being logged in the console, but I can't render it in my Next.js component. I am using PostgreSQL in ...

The React component in Microsoft Graph Toolkit is failing to update when the state of its props changes

I have been experimenting with the Microsoft Graph Toolkit React component by implementing templates as outlined here. I passed a react state as props to the component and noticed that the component does not re-render when the state changes, unlike a regul ...

Changing the arrow in jQuery's slideToggle for different div elements is a breeze

Good day, I'm struggling with getting the arrow switch to work correctly for slideToggle. Even though I have three of them, the arrow changes only for the first one - no matter which div I click on. Any suggestions on what I might be missing? Thank yo ...