You can use <link rel="stylesheet" type="text/css" href="%PUBLIC_URL%/index.css" /> in the index.html

Answer from xiaoming on Stack Overflow
🌐
GitHub
github.com › facebook › create-react-app › issues › 6368
Webpack CSS-build behaves differently in production than in development · Issue #6368 · facebook/create-react-app
December 31, 2018 - Well, I'm noticing that when running npm start the app works perfectly in development. But when running npm run build and then deploy it to a staging environment, the app has slight visual differences, as if "somefile.scss" had higher specificity over "someotherfile.scss" (the opposite should be true). Does webpack do something different when building stylesheets for production?
Author   pgarciacamou
🌐
GitHub
github.com › facebook › create-react-app › issues › 4369
js and css files are not getting loaded in production environment. JS and CSS are again loading index.html · Issue #4369 · facebook/create-react-app
When i am hoisting application in local , things are working fine , but when i try to host the same in production environment , nothing is getting loaded . It is coming to index.html , but the js and css are not getting loaded. Production URL is -> https://stg.abc.com/tools/forecaster. Local URL -> http://localhost:8081/tools/forecaster ... import React from 'react' import { BrowserRouter as Router, Route } from 'react-router-dom'; import login from './components/login'; const myTool = () => ( <Router> <div> <Route exact path="/tools/forecaster" component={login}/> <Route exact path="/tools/forecaster_hs" component={login}/> </div> </Router> ) export default myTool
🌐
Stack Overflow
stackoverflow.com › questions › 54051772 › compiled-css-is-not-being-attached-to-jsx-in-react-build
reactjs - Compiled CSS is not being attached to JSX in react build - Stack Overflow
{ test: /\.css$/, exclude: /node_modules/, loader: ExtractTextPlugin.extract( Object.assign( { fallback: { loader: require.resolve('style-loader'), options: { hmr: false, modules: true, localIdentName: '[name]__[local]__[hash:base64:5]' }, }, use: [ { loader: require.resolve('css-loader'), options: { importLoaders: 1, minimize: true, sourceMap: shouldUseSourceMap, }, }, { loader: require.resolve('postcss-loader'), options: { // Necessary for external CSS imports to work // https://github.com/facebookincubator/create-react-app/issues/2677 ident: 'postcss', plugins: () => [ require('postcss-flex
🌐
Stack Overflow
stackoverflow.com › questions › 46456733 › css-not-loaded-in-production-with-react-and-webpack
reactjs - CSS not loaded in production with React and Webpack - Stack Overflow
// Development builds of React are slow and not intended for production. if (env.stringified['process.env'].NODE_ENV !== '"production"') { throw new Error('Production builds must have NODE_ENV=production.'); } // Note: defined here because it will be used more than once. const cssFilename = 'static/css/[name].[contenthash:8].css'; // ExtractTextPlugin expects the build output to be flat.
🌐
GitHub
github.com › facebook › create-react-app › issues › 5140
react-scripts@next drops css import in production build · Issue #5140 · facebook/create-react-app
observe that there are exactly two commits. one is a fresh commit of npx create-react-app@next, the other adds a component lib & style sheet · yarn start. observe a styles applied. kill the process · yarn build. serve the production build. observe missing styles. ... this dependency shows up in dev mode in the dev server, but no such CSS is generated into the build dir.
🌐
Reddit
reddit.com › r/reactjs › css custom properties (variables) not working in react production build
r/reactjs on Reddit: CSS custom properties (variables) not working in react production build
January 25, 2022 -

I have several custom css properties defined on the root, and they are working fine on the development build, however they aren't loading on the production build. The custom properties are defined in index.css.

:root {
  --light-theme-background-color: #fafafa;
  --light-theme-text-color: #333;
  --light-theme-active-color: #cbcbcb;
  --dark-theme-background-color: #1d2327;
  --dark-theme-text-color: #227093;
  --dark-theme-active-color: #343434;
}

In the dev tools the custom properties are grayed out and when I hover I get the message that they are not defined.

https://imgur.com/a/Jd1UYzh

🌐
GitHub
github.com › facebook › create-react-app › issues › 4715
css modules not working in production (heroku) · Issue #4715 · facebook/create-react-app
@keerkeerhi I change this file and it's work on dev but not on production. how file node_modules\react-scripts\config\webpack.config.dev.js relative to prod version? ... @OriAmir did you end up giving the alpha build a try? That's the easiest solution, or you have to use something like https://github.com/codebandits/react-app-rewire-css-modules
🌐
Reddit
reddit.com › r/reactjs › create-react-app not building when css is in src folder
r/reactjs on Reddit: Create-react-app not building when css is in src folder
February 12, 2018 -

I have been using CRA for my project and for some reason it will not build (or deploy to heroku) when my css file is in any folder other than public. I have googled all over the internet and the only similar question had a problem solved by their own error in css. I have linted the css file and have found only warnings.

This is my current file structure

In index.js inside my src folder I have:

import React from 'react';
import ReactDOM from 'react-dom';
import './components/index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

And in every component file I have an import statement for the CSS.

I have tried moving the css file inside the src folder and changing the paths, but the only place it will successfully build is when it's inside the public folder with index.html and I link to the file.

I keep getting the error:

 ./src/index.css
Module build failed: ModuleBuildError: Module build failed: TypeError: Cannot read property 'length' of undefined
at Array.forEach (<anonymous>)
    at <anonymous>

EDIT: I'm constantly doing trial and error to find the issue and it seems like it really is something that webpack may not be able to process in my css file. If I comment out the homepage.css file, it will build and work. I am currently trying to find the property that it cannot read. Anyone know if it's a css grid thing that it can't compile or if there is a list of properties that webpack can't compile?

EDIT 2: Ok guys I've spent like maybe 5 hours on this (including time from last night) and I finally find the problem. It seems that cra doesn't like me making my code cleaner and copying a banner gradient from Wes Bos' tutorial.

  background: linear-gradient(to var(--direction, left), var(--yellow), transparent);

This was the issue. The var(--direction, left) does not work with the css-compiler (i'm guessing) in cra. This code was used to make THIS type of banner and to make less code. It works in my local dev on Chrome and Firefox, but I guess it's a no-no for cra. Hope this may help anyone in the future!

Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 44738197 › ejected-create-react-app-build-production-css-not-working-working-correctly
reactjs - ejected create_react_app & build (production) css not working working correctly - Stack Overflow
I have an application that was created from create_react_app then ejected, with no modifications. Everything works as expected when running the dev version. Unfortunately when I do npm run build and run this via serve -s build my styles are not working. The .css files are being found and compiled ...
🌐
Stack Overflow
stackoverflow.com › questions › 66973112 › css-modules-not-working-on-production-build
reactjs - Css modules not working on production build - Stack Overflow
When I run npm build I notice that the react bootstrap is loaded but the module.css that I coded isn't, so my page looks horrid without styles. Can you offer any pointers on how I should proceed? Note: it's working perfectly fine running a server on 3000 on npm start and it is only on production ...
🌐
Netlify
answers.netlify.com › support
Some CSS styles not work on deployment - Support - Netlify Support Forums
May 16, 2023 - Hi there ! I made my own program with Create-react-app and used CSS Module for styling. This is the link of my project: GitHub - sajjadpaknia/dalbi Some styles disappear when deployed. Some elements are not styled if they are displayed correctly on local. Thank you for helping me.
🌐
GitHub
github.com › facebook › create-react-app › issues › 8375
I'm facing issues with CSS after I run build. · Issue #8375 · facebook/create-react-app
Describe the bug: CSS Works fine in local but it ruins the css after i run build to run via the nginx in production. I see the same css issues if i run with python server on my local computer. So there's some issue in the way build is be...
🌐
DhiWise
dhiwise.com › post › troubleshooting-guide-how-to-fix-react-css-not-applying
Troubleshooting Guide: Resolving React CSS Not Applying
May 30, 2024 - Verify that your CSS file is being loaded correctly in your React application. Check the network tab in browser dev tools to ensure that the CSS file is not missing. Use developer tools to inspect elements and see which styles are being applied ...
🌐
Stack Overflow
stackoverflow.com › questions › 75119551 › production-build-in-react-is-not-loading-css-file
reactjs - Production build in react is not loading css file - Stack Overflow
Only output for scss is in development mode which I'm going to put into question aswell because it is a little bit long. ... Check your nginx is correctly configured to serve css files.
🌐
GitHub
github.com › JedWatson › react-select › issues › 3309
Some css styles are not created in production but work in development · Issue #3309 · JedWatson/react-select
September 24, 2018 - The dynamic css rules for the outer divs never get created in the emotion stylesheet. They are, however, set on the divs in the DOM. The rest of the dynamic css rules (e.g. on the options when you click on the control) do get created in the emotion stylesheet. This only happens on a few pages in our app, while other parts work as expected.
Author   jjlauer
🌐
Render
community.render.com › t › css-errors-when-deploying-react-app › 8053
CSS errors when deploying React app - Render
November 8, 2022 - Hello! I’ve been having some troubles deploying my React app as a static app. The app is correctly deployed and working well, but my App.css file is not taken into account. When running the app locally, I’ve got no issue, but when deploying on Render, the styles specified in the App.css ...
🌐
Quora
quora.com › Why-is-React-not-reading-a-CSS-file-React-js
Why is React not reading a CSS file (React.js)? - Quora
Answer: This is not a React problem, it is either a loading or css (class specificity, etc) problem. In the css file, add an [code ]!important[/code] css rule to turn all text red, targeting the body tag.