msw-storybook-addon: Webpack 5 Throws ModuleNotFoundError
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?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (5 by maintainers)
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:
Then in
.storybook/main.js
I have a custom webpackFinal setup to modify SB’s pollyfil configsNowadays setting up Storybook feels like performing surgery !
Hi, @ninjarogue. I believe I’ve replied to you in another thread. You have the mistake of missing
setupWorker
andsetupServer
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.That seems like it! However I don’t understand why it would happen if that code is supposed to be lazy loaded 🤔 I’d love to check about this issue, though I’m not sure how to reproduce it. Can anyone provide a minimal repro?
Edit: I managed to reproduce it. Will investigate further!