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.

Styled-components css not loading in prod mode.

See original GitHub issue

Prerequisites

  • Using yarn
  • Using an up-to-date master branch
  • Using latest version of devtools. Check the docs for how to update
  • For issue in production release, add devtools output of DEBUG_PROD=true yarn build && yarn start there is no error at all, just every dive or component is not loading its css, or dev its working fine but on prod its not working.

Expected Behavior

should load all the css in prod build as its loading in dev env

Current Behavior

not loading any css at all in prod,

Steps to Reproduce

just use one styled-component with css in tsx file, it will not load the css. using styled-component 5.2.0

Possible Solution (Not obligatory)

Context

Your Environment

  • Node version : 10.15.0
  • electron-react-boilerplate version or branch : updated master branch
  • Operating System and version : MacOS and windows
  • Link to your project : not available

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
amilajackcommented, Oct 7, 2020

Yea that’s correct

1reaction
richard-livingstoncommented, Sep 20, 2021

This is still an issue an issue in version 3.0.2 (latest), please can you reopen it @awaisayub149. Following @codingedgar’s advice fixes css modules in production but breaks global css, the following code will enable both…

webpack.config.renderer.prod.babel.js: module.rules

{
	// CSS/SCSS
	test: /\.global\.s?css$/,
	use: [
	  {
		loader: MiniCssExtractPlugin.loader,
		options: {
		  // `./dist` can't be inerhited for publicPath for styles. Otherwise generated paths will be ./dist/dist
		  publicPath: './',
		  esModule: false
		},
	  },
	  {
		loader: 'css-loader',
		options: {
			sourceMap: process.env.DEBUG_PROD === 'true'
		},
	  },
	  'sass-loader',
	],
},
{
	// CSS/SCSS
	test: /^((?!\.global).)*\.s?css$/,
	use: [
	  {
		loader: MiniCssExtractPlugin.loader,
		options: {
		  // `./dist` can't be inerhited for publicPath for styles. Otherwise generated paths will be ./dist/dist
		  publicPath: './',
		  esModule: false
		},
	  },
	  {
		loader: 'css-loader',
		options: {
			modules: {
				localIdentName: '[name]__[local]__[hash:base64:5]',
			},
			sourceMap: process.env.DEBUG_PROD === 'true',
			importLoaders: 1,
		},
	  },
	  'sass-loader',
	],
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

react styled components not working in production
I have been able to work with styled-components on webpack dev server without any problem but the styles are not getting added when...
Read more >
styled-components does not inject styles in head #2254 - GitHub
S-C loads just fine, just the CSS injection isn't working. SSR works fine too (I have it enabled in dev mode as well),...
Read more >
Next.js and Styled-Components: style loading issue
Have you tried using Styled-Components with your Next.js app but can't get the styles to load properly? This is because the server-side ......
Read more >
FAQs - styled-components
However, there is a CSS solution to the problem in the font-display CSS rule. By setting the rule to "fallback" mode, once a...
Read more >
Using Styled Components - Expo Documentation
Styled Components is a CSS-in-JS solution that enables you to create React components with a given style very easily. Using styled-components with Expo, ......
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