question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent loading order of CSS Modules + global CSS

See original GitHub issue

Bug report

Describe the bug

I have a global CSS imported in /pages/_app.js and name.module.css imported in a page. In production mode the CSS Module is loaded after the global CSS. In development mode, the CSS Module is loaded before the global CSS.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

Repository with code needed to reproduce the issue

  1. Add a global style within pages/_app.js
  2. Add and import a CSS Module
  3. Add CSS classes to both files with the same specificity, so the order of including files resolves the conflict.
  4. Run “dev” script.
  5. See order of CSS in a browser.
  6. Run “build” and “start” scripts.
  7. See different order of CSS in a browser.

Expected behavior

In development mode the global CSS should be loaded first and CSS Modules later on, the same as it works in production.

System information

  • OS: macOS 10.15.2
  • Browser: Chrome 79.0.3945.130
  • Version of Next.js: 9.2.0

Additional context

The page looks different in dev and production modes because of CSS overriding.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:39
  • Comments:27 (13 by maintainers)

github_iconTop GitHub Comments

15reactions
sparkertimecommented, Apr 15, 2020

If anyone on this thread is desperate for this fix, it is available in the 9.3.6-canary.0 next.js release (thanks @Timer for turning that around so quickly!)

14reactions
valsecommented, Mar 18, 2020

We have the same issue using the version 9.3.0 with SASS globals in _app and the CSS modules for single components

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - CSS module classes work on development, but are ...
This breaks my app on production, but everything seems to work just fine on development. Here's an example: ///mobile.module.css .expandIcon { ...
Read more >
Using CSS modules in React - Bootcamp
To import a CSS Module into the corresponding component, import the css modules stylesheet as styles or [name]Styles : In JSX, use the...
Read more >
Basic Features: Built-in CSS Support - Next.js
Next.js supports including CSS files as Global CSS or CSS Modules, using `styled-jsx` for CSS-in-JS, or any other CSS-in-JS solution! Learn more here....
Read more >
Can CSS Modules solve all the problems? - YIOU CHEN
The CSS files should have a very clear connection with the JavaScript file. Usually, one component corresponds to one CSS module. This way,...
Read more >
Standard Styling with Global CSS Files - Gatsby
The biggest problem with global CSS files is the risk of name conflicts and side effects like unintended inheritance. CSS methodologies like BEM...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found