Inconsistent loading order of CSS Modules + global CSS
See original GitHub issueBug 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
- Add a global style within pages/_app.js
- Add and import a CSS Module
- Add CSS classes to both files with the same specificity, so the order of including files resolves the conflict.
- Run “dev” script.
- See order of CSS in a browser.
- Run “build” and “start” scripts.
- 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:
- Created 4 years ago
- Reactions:39
- Comments:27 (13 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

If anyone on this thread is desperate for this fix, it is available in the
9.3.6-canary.0next.js release (thanks @Timer for turning that around so quickly!)We have the same issue using the version 9.3.0 with SASS globals in _app and the CSS modules for single components