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.

Incorrect order of CSS in build version

See original GitHub issue

Is this a bug report?

Yes

Environment

npx create-react-app --info prints empty result for some reason.

Steps to Reproduce

Using CRA 3.0.1.

  1. create-react-app style_test
  2. npm i bootstrap@3.3.7 --save
  3. In index.js import two CSS files - first, a reset CSS, second, the bootstrap CSS.
  4. Run dev server and production builds and compare results.

Expected Behavior

Both dev server and production builds should display text using bootstrap CSS.

Actual Behavior

Dev server works as expected, but production build contains two CSS chunks, one with bootstrap code and another with reset CSS, loaded in wrong order (bootstrap first). As a result, in production version text is not styled.

Bootstrap (and only bootstrap) appears in 2.*.chunk.css, while reset CSS and all my sass styles end up in main.*.chunk.css. What is the benefit of using two chunks, anyway? Just faster load times due to parallel loading of both scripts?

Reproducible Demo

https://github.com/d07RiV/style_test

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:34
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
sliptypecommented, Aug 30, 2019

I was able to resolve this by importing my css files from within my sass entrypoint file.

main.scss

@import 'node_modules/bootstrap/scss/bootstrap.scss';
@import 'node_modules/react-bootstrap-typeahead/css/Typeahead';

It seems like this will preserve the order correctly

3reactions
m-nathanicommented, Jan 22, 2022

Wow… I faced this issue in create-react-app 4 …

The Dev server css order changed to in production build,

For me css of a node_module is taking preceding over my css.

Is there any possible solution that cra provides ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

create-react-app npm run build wrong css order - Stack Overflow
In development this works just fine, but using the compiled css after running npm run build makes the responsive styling messed up. After...
Read more >
Optimizing Performance - React
To create a production build, make sure that you add these transforms (the order matters): The envify transform ensures the right build environment...
Read more >
react-app-rewired - npm
1) Install react-app-rewired · 2) Create a config-overrides.js file in the root directory · 3) 'Flip' the existing calls to react-scripts in npm ......
Read more >
How To Set Up a React Project with Create React App
Then you will run the build script to create a minified version. ... App.css App.js App.test.js index.css index.js logo.svg serviceWorker.js ...
Read more >
How to tell ReactJS to build project in Production mode
Your JavaScript and CSS files will be inside the build/static directory. A number of .js files are generated and placed inside the ...
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