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.

css modules not working in production (heroku)

See original GitHub issue

I read all possible question about this topic but not found anything that help me.

I build react app using create-react-app and want to use css modules. So I change the weback files found in node_modules/react-scripts/config because I don’t want to ‘eject’ the config files.

On dev everything works well and it’s recognize the modules , but on production it’s not working. ( in dev not exist ‘ExtractTextPlugin’ plugin anyway)

So, laster I try to ‘eject’ the configuration files and then do change the web pack prod file that found in the src/config and it’s work, but I really don’t want to eject all configuration files for this.

I try also to copy exactly the same web pack.config.prod.js file that work after eject but for some reason it’s doesn’t help

this is the code from my web pack.config.prod.js:

        test: /\.css$/,
        loader: ExtractTextPlugin.extract(
          Object.assign(
            {
              fallback: {
                loader: require.resolve('style-loader'),
                options: {
                  hmr: false,
                },
              },
              use: [
                {
                  loader: require.resolve('css-loader'),
                  options: {
                    importLoaders: 1,
                    modules: true,
                    localIdentName: '[name]__[local]__[hash:64:5]',
                    //   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-flexbugs-fixes'),
                      autoprefixer({
                        browsers: [
                          '>1%',
                          'last 4 versions',
                          'Firefox ESR',
                          'not ie < 9', // React doesn't support IE8 anyway
                        ],
                        flexbox: 'no-2009',
                      }),
                    ],
                  },
                },
              ],
            },
            extractTextPluginOptions
          )
        ),
        // Note: this won't work without `new ExtractTextPlugin()` in `plugins`.

I try many other configuration for this in the prod file but nothing effect on prod

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12

github_iconTop GitHub Comments

2reactions
bugzpoddercommented, Jul 2, 2018

@OriAmir While the alpha version isn’t without bugs (see issues opened), I think as long as you test your production build on a staging server and make sure everything works correctly you should be fine (because it is basically building your source code and you’ve tested the final result). Under the hood react-scripts only really uses beta version of babel 7. Personally I’ve been using the alpha build in production for a couple of months now. Whenever a new alpha is released you can always update the version number in package.json very much like any other package.

1reaction
bugzpoddercommented, Oct 26, 2018

@OriAmir give it a try, it should be stable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

css modules in create-react-app not working in production ...
I build react app using create-react-app and want to use css modules. So I change the weback files found in node_modules/react-scripts/config ...
Read more >
Why are my CSS/JS changes not showing up in my Node app?
Issue. Deployed changes to CSS or javascript assets are not showing up after deploying a Node app. Resolution. If your app requires a...
Read more >
How To Optimize React App For Production And Deploy It To ...
This is obviously not good. As you never want to see your code by anyone once your app is in production. So to...
Read more >
Troubleshooting | Vite Ruby
Your bin/bundle was not generated by Bundler # ... It's likely that your bin/bundle was generated by an older version of bundler than...
Read more >
Heroku can't locate CSS files in my react project when building
You need to add ./ at the beginning of your import for your transpiler to understand that it should look for a file...
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