styleguidist / react-styleguidist

Isolated React component development environment with a living style guide
https://react-styleguidist.js.org/
MIT License
10.83k stars 1.44k forks source link

Webpack 5 does not return compiler object with callback #2153

Open KilianB opened 1 year ago

KilianB commented 1 year ago

Current behavior

Attempting to run the build command fails with webpack 5.88.2 fails with the following error message:

TypeError: Cannot read properties of null (reading 'options') TypeError: Cannot read properties of null (reading 'options') at commandBuild (G:\git\react-date-range\node_modules\react-styleguidist\lib\bin\styleguidist.js:115:42)

The exact same issue has been reported and closed here: identical to the issues https://github.com/styleguidist/react-styleguidist/issues/1786 && https://github.com/styleguidist/react-styleguidist/issues/2143 even though it still is present with the most current version

According to the webpack docs a compiler object is not returned with a callback: https://webpack.js.org/api/node The issue can temporarily fixed by modifying the files in the bin directory: https://github.com/styleguidist/react-styleguidist/blob/0802ffbe716fef22086f87f5c6a9caec2f9126d1/src/scripts/build.ts#L9

Get rid of the callback:

function build(config) {
  const webpackWithConfig =  (0, _webpack.default)((0, _makeWebpackConfig.default)(config, 'production'));
  return webpackWithConfig;
}

and move the callback to the run command: ` /lib/bin/styleguidist.js>commandBuild

  const compiler = build(config);

  compiler.run( err => {
    if (err) {
      console.error(err);
      process.exit(1);
    } else if (config.printBuildInstructions) {
      config.printBuildInstructions(config);
    } else {
      printBuildInstructions(config);
    }
  });
rolandjitsu commented 3 days ago

If someone were to make a PR, would it be reviewed and possibly merged?

cc @ThomasRoest