question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack 5 Throws ModuleNotFoundError

See original GitHub issue

Hi, I’m using Webpack^5.46.0, @storybook/react^6.3.4, msw-storybook-addon^1.2.0, and msw^0.35.0. I have Storybook configured to use Webpack 5. Whenever the Storybook dev server is running and I modify the preview to initialize the worker, it works. But when I shutdown the server and restart it, it breaks with the following error:

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it

This error is thrown multiple times for multiple packages. Has this been reported before? Any possible fix?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
mouhannad-shcommented, Aug 24, 2021

Went through the same thing just now… following the error traces. I tried this and it worked for me (looking for a better solution 😄 )

I followed the setup guide from storybook to support webpack 5

my deps look like this now:

"devDependencies": {
    "@storybook/addon-actions": "^6.4.0-alpha.11",
    "@storybook/addon-essentials": "^6.4.0-alpha.11",
    "@storybook/addon-links": "^6.4.0-alpha.11",
    "@storybook/builder-webpack5": "^6.4.0-alpha.11",
    "@storybook/manager-webpack5": "^6.4.0-alpha.11",
    "@storybook/react": "^6.4.0-alpha.11",
    "msw": "^0.35.0",
    "msw-storybook-addon": "^1.2.0"
},
"resolutions": {
    "webpack": "^5.45.1",
    "css-loader": "^5.0.0",
    "dotenv-webpack": "^6.0.0",
    "html-webpack-plugin": "^5.3.2",
    "style-loader": "^2.0.0",
    "terser-webpack-plugin": "^5.1.4",
    "webpack-dev-middleware": "^4.1.0",
    "webpack-virtual-modules": "^0.4.2",
  }

Then in .storybook/main.js I have a custom webpackFinal setup to modify SB’s pollyfil configs

webpackFinal: config => {
    return {
      ...config,
      resolve: {
        ...config.resolve,
        modules: [path.resolve("./src"), ...config.resolve.modules],
        fallback: {
           timers: false,
           tty: false,
           os: false,
           http: false,
           https: false,
           zlib: false,
           util: false,
           ...config.resolve.fallback,
        }
      }
    };
  }

Nowadays setting up Storybook feels like performing surgery !

1reaction
kettanaitocommented, Mar 8, 2022

Hi, @ninjarogue. I believe I’ve replied to you in another thread. You have the mistake of missing setupWorker and setupServer in the same module. Those functions are meant for different environments and you cannot import them in a single module. Please split them by modules as shown in the examples and the issue will be gone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack 5 and Storybook 6 integration throws an error in ...
Basically the error is coming from the marked line in /node_modules/webpack/lib/DefinePlugin.js once running for the first time npm run ...
Read more >
Webpack 5 errors | ImmutableX Documentation
The reason for this error is that create-react-app uses a version of webpack greater than 5, which, unlike versions < 5, does not...
Read more >
webpack Module not found: Error: Can't resolve classNames ...
Coding example for the question webpack Module not found: Error: Can't resolve ... importing it to react application throws Module not found error...
Read more >
module not found error | can not resolve react dom module
JS - JavaScript. module not found error | can not resolve react dom module. 12,501 views12K views. Mar 16, 2022. 29. Dislike. Share....
Read more >
module not found error can't resolve 'fs' react js - You.com
Your quick fix is to take react scripts down to v4 until a fix for v5 is in place unless you are comfortable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found