Skip to content

Webpack 5 does not return compiler object with callback #2153

Open
@KilianB

Description

@KilianB

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 #1786 && #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:

return webpack(makeWebpackConfig(config, 'production'), (err, stats) => {

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);
    }
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions