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.

Not work only server side render

See original GitHub issue

Here is minimun reproduction

I only config webpack for server compile:

const path = require('path')

module.exports = {
  mode: 'development',
  entry: path.resolve(__dirname, 'src/index.jsx'),
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'index.js'
  },
  resolve: {
    extensions: ['*', '.js', '.jsx', '.ts', '.tsx', '.less', '.css']
  },
  target: 'node',
  module: {
    rules: [
      {
        test: /\.less$/,
        use: [
          'isomorphic-style-loader',
          {
            loader: 'css-loader',
            options: {
              onlyLocals: true,
              localsConvention: 'camelCase',
              importLoaders: 1,
              modules: {
                localIdentName: '[path][name]__[local]'
              }
            }
          },
          // 'css-loader',
          {
            loader: 'less-loader',
            options: {
              sourceMap: true,
              relative: true
            }
          }
        ]
      },
      {
        test: /\.jsx?$/,
        use: ["babel-loader"]
      }
    ]
  }
}

and get this:

image

I found a similar issue, but there is not a clear anwser ~

Did I missing something ?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

13reactions
AftabFalakcommented, Aug 25, 2020

Thanks @lfscheidegger i had same issue and after adding esModule:false is working now

here is my webpack.server.js file

module: {
   rules: [
     {
       test: /\.css$/,
       use: [
         {
           loader: 'isomorphic-style-loader'
         },
         {
           loader: 'css-loader',
           options: {
             modules: true,
             esModule: false,
     
           }
         }
       ]
     }
     
   ]
 },

Happy Coding : )

5reactions
lfscheideggercommented, Aug 16, 2020

I ran into a similar problem, and I found a workaround for my case - maybe it’ll work for other people too.

TL;DR - if you’re using webpack4, set the esModule option in css-loader to false.

I’m no expert here by any means, but here’s how I debugged this: I had my insertCss function print out the css values it was getting (which ultimately come from webpack when you call something like import css from './styles.css'). In my case I use sass-loader, but I actually think that’s irrelevant here.

In an old version of my project (which used webpack3 and isomorphic-style-loader 4), the output of printing those modules was an object with _getContent, _setCss, and _insertCss. This is expected, from looking at https://github.com/kriasoft/isomorphic-style-loader/blob/master/src/index.js#L26.

However, the object printed in the old build also included the non-module -> module mapping for all the css classes. And crucially, those keys (which come from https://github.com/kriasoft/isomorphic-style-loader/blob/master/src/index.js#L25) seem to be missing when this issue reproduces.

I then monkey-patched the installed isomorphic-style-loader (I’m on 5.1.0) to print out css.locals, and as suspected, that’s always undefined.

This made me suspect that the issue wasn’t directly with isomorphic-style-loader, but with whatever changed in css-loader between webpack3 and webpack4. I more or less guessed at some options until I verified that setting esModule: false in the css-loader options seems to bring back the old behavior.

Worked for me, but YMMV!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Server-Side Rendering Alone Is Not the Solution
Speeding Up Load Times With Server-Side Rendering ... Of course, caching is only a solution for content that does not contain user data....
Read more >
Server-side rendering not working on production Next.js
getServerSideProps only works in page components. Does this answer your question: NEXTJS: getServerSideProps not working into components?
Read more >
How to Disable Server-Side Rendering (SSR) in Next.js
Step 1: Rewrite All Requests to pages/index.js · Step 2: Disable SSR for Page Content · Step 3: Check that Everything Works with...
Read more >
Server-side rendering - Apollo GraphQL Docs
Server -side rendering (SSR) is a performance optimization for modern web apps. It enables you to render your app's initial state to raw...
Read more >
React Server Components. - It's not server-side rendering.
Whereas SSR is only used once for the initial rendering, Server Components can be re-fetched multiple times to re-render the data (in 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