DEV Community

SeongKuk Han
SeongKuk Han

Posted on

Storybook plugins "push of undefined" error in webpackFinal after upgrading from webpack4 to webpack5

webpackFinal: async (config) => {
    config.resolve.plugins.push(new TsconfigPathsPlugin({}));

    return config;
  },
Enter fullscreen mode Exit fullscreen mode

TypeError: Cannot read property 'push' of undefined
The error occurred after upgrading. from webpack4 to webpack5.

webpackFinal: async (config) => {
    if (config.resolve.plugins !== undefined) {
      config.resolve.plugins.push(new TsconfigPathsPlugin({}));
    } else {
      config.resolve.plugins = [new TsconfigPathsPlugin({})];
    }

    return config;
  },
Enter fullscreen mode Exit fullscreen mode

I thought that config.resolve.plugins is possible to be not undefined in the future. This is why I first checked whether config.resolve.plugins is undefined or not then replace config.resolve.plugins or push the plugin into config.resolve.plugins.

Top comments (0)