document is not defined error in server side rendering code example

Example: document is not defined error in server side rendering

3

Root cause: the plugin style-loader will type CSS into js to generate the style label in js, such as document.createelement ("style"); but the server doesn't have the document api. So it crashed.

Try using the mini-css-extract-plugin to pull the CSS code out of the js file. Avoid using document.creatEelement ("style") in js file;
Post a section of my configuration

const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  mode: process.env.NODE_ENV === 'development' ? 'development' : 'production',
  module: {
    rules: [
      {
        test: /\.css$/,
        exclude: /node_modules/,
        use: [MiniCssExtractPlugin.loader, 'css-loader']
        // use: ['style-loader', 'css-loader']
      }
    ],
  },
  plugins: [new MiniCssExtractPlugin()],

};