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

Executing a function within another function (triggering the logout action by clicking the logout link) in ReactJS

Is there a way to access a method outside the render function and call it inside another function in order to log out the user with a simple click? I encountered the following error: Cannot read property 'AuthLogout' of undefined Let me shar ...

Using React, the value of the <input> element will remain the same even after editing

I am facing an issue with my edit page where I am unable to update the details of the existing object. Despite having input elements to contain the values, when I try to change them on the view by deleting or typing new values, they do not get updated. C ...

A pair of functions featured in a React-Native event

Is it possible to include two functions in an event like onValueChange? I attempted the following: onValueChange={(selected) => this.setState({selected}),this.state.eventOnChange}> ...

Is there a method to streamline the commands needed to run a node application that has been installed via npm?

I recently developed a small npm package and successfully deployed it. This package is essentially a CLI tool built in Node.js, and I am currently looking for ways to streamline the execution process. Currently, in order to use the CLI, I have to follow t ...

Instruct npm to remove dependencies that are no longer necessary

After adding a few libraries to my package.json file, I realized that they are no longer needed. Is there a command line parameter for npm install that can be used to remove unnecessary packages from node_modules directory that are not in package.json anym ...

What are the steps to effectively implement the useEffect hook in React?

I'm facing an issue where I am trying to return a function that utilizes useEffect from a custom usehook, but I keep getting the error "useEffect is called in a function which is neither a react function component nor a custom hook." Here's what ...

ToggleButton4 Framework is a user-friendly tool for creating interactive

I am currently working with Bootstrap 4 to design a toggle button; however, when I click the button, the checkbox does not update, despite the fact that the active class is being applied. Even when I use $('.btn-group-toggle').button('toggl ...

After applying the withStyles and withTranslation higher order components to a React component, a Typescript error is displayed

Trying to create a React component using Typescript, incorporating withStyles from @material-ui/core and withTranslation from react-i18next, both of which are Higher Order Components (HOC). Encountering a typescript error when using them together. Specif ...

Providing pre-compiled native binaries through npm distribution

Can native binaries be distributed using npm, and is there any documentation available on this topic? ...

Fade out transitions in Next JS with Framer Motion

Working on implementing a fade in/out effect using framer-motion and Next.js, but facing an issue where it never fades out. I have knowledge that AnimatePresence allows components to animate out when they're removed from the React tree. which seems to ...

How can I maintain the router query when refreshing a page in Next.js?

I am facing an issue with a dynamic page and URL that is rendered on the client side. Below is the code snippet for the link that navigates to the second page: <Link href= {{ pathname: '/dashboard/[orderdetail]', query: { id: `${orderID}` } ...

conceal the mustard-colored dots within the overlay

Whenever I trigger the link, a modal window pops up, but it comes with an unwanted black background color and yellow dots. How can I prevent the yellow dots from showing up on the overlay? http://jsfiddle.net/y88WX/18/embedded/result/ <nav class="da-d ...

Setting up WebPack for TypeScript with import functionality

A tutorial on webpack configuration for typescript typically demonstrates the following: const path = require('path'); module.exports = { ... } Is it more advantageous to utilize ES modules and configure it with import statements instead? Or is ...

Steps for configuring a Dockerfile ARG within Github actions

I am facing an issue with deploying my Node.js service using a Dockerfile and Github actions to push it to my Digitalocean registry. My Node.js service requires a private package hosted on npm.js registry, which I have set up with an ARG in the Dockerfile ...

What are the steps for updating an NPM package that was installed from a Git repository?

I'm struggling to understand how to update a package that was installed from a git repository. Let's say I have a package located at git+ssh://<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4b3bda094b3bda0b8b5b6fab1 ...

What is the process for deprecating a project dependency in the package.json file?

Is it feasible to designate a project dependency as outdated without completely removing it from the project? This is to prevent other developers from utilizing it in future projects. I am currently working on a project that was initially developed using ...

When npm 1.3.11 installs PhoneGap on Mac OSX, it generates a "Password:" directory path

When attempting to install Phonegap on Mac 10.8.5, using the following commands: sudo npm install -g phonegap or npm install -g phonegap The result includes the following output: /Users/eric/Password:/usr/local/bin/phonegap -> /Users/eric/Passw ...

Having trouble launching simple ionic template: Issue with locating module 'fast-deep-equal'

Recently I started using Ionic and followed the steps to install the basic blank template as shown below. First, I installed Ionic and Cordova by running the command: npm install -g ionic Cordova. After that, I created my first Ionic project using the f ...

Update the objects with new values when the user makes changes in the

I am working with dynamically created input fields const [data, setData] = useState({ native: [{}], rolls: [{}] }) // initial data {navtive?.map((item, index) => { return ( <input type="text" name={item.id} ...

Transmit Data Efficiently Using Axios

Having an issue where when sending multiple data with axios, the image in formdata does not send. However, when I only send the formdata it works fine. If anyone knows how to successfully send multiple data in axios, please provide a solution. const onS ...