Error: Couldn't find a style target. It started to appear after SSR with React implementation. How to fix?

Viewed 380

I had a CSR app and now implemented Server-Side Rendering (SSR) with React, and get this error Error: Couldn't find a style target

We used reactDOMserver, react-app-wire, with webpack-override file See webpack configs below:

const { resolve } = require("path");
require("ignore-styles");

module.exports = {
  webpack: function (config) {
    config.entry = resolve(dirname, "../client/src/ssr");
    config.optimization = undefined;
    config.output = {
      filename: "ssr.js",
      globalObject: 'this',
      libraryTarget: "commonjs",
      path: resolve(dirname, "../client/build"),
    };
    return config;
  },
};

from server

app.get("^/$", (req, res) => {
  Object.assign(global, {
    navigation: {},
    window: ssr.getWindow(),
    navigator: {
      userAgent: req.headers["user-agent"],
    },
    global: {},
    document:ssr.ssrDocument
  });
  const App = require("./build/ssr");
  const context = {};

  let app = App.default(req.url, context);

then res,render app

AND SSR JS FILE

ssr.js file  :
import { renderToString } from "react-dom/server";
for renderToString(
....
<App/>
....
)

And received Error: Couldn't find a style target I had a CSR app and now implemented Server-Side Rendering (SSR) with React, and get this error Error: Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid Get this error when I run the server and try to access the page.


We also tried other approaches with these loaders: css-loader, sass loader and style-loader and even with isomorphic-style-loader They led to the error with No PostCSS config and after fixing this by adding to the project postcss.config.js file AND AFTER we received same error about style target and additional error with antd Error: No PostCSS Config found in: D:_PROJECT....\client\node_modules\antd\dist


Tech sack in use: nodejs, reactjs, antdesign, babel and webpack. I already tried a lot of solutions from StackOverflow and other sources, nothing helped!

Please, help me to solve it.

Thank you!

1 Answers
Related