Mock Service Worker is one of the nicest ways to mock APIs in the browser, and Nx is a great home for a monorepo. Getting the two to work together takes a couple of steps that aren’t obvious from either project’s docs.
👉 Continue reading on my blog: 🚧 Configure MSW in NX
Top comments (3)
Very useful article @iamandrewluca . I was able to get my Nx app running with MSW without any issues. Also got Jest to recognize MSW.
However, having trouble with Storybook. It seems to find the handlers but has trouble loading
mockServiceWorker.js. Here's the error message:Any idea what could be going wrong? Here's my repo.
yarn storybook:appto start storybook, then try CartView or CatalogView. You will see "Network Error".TIA.
When your run storybook, it starts standalone without app/lib configuration even if is run through nx.
Your current configuration is specifically for react-test-shop.
You will need to configure msw separately for storybook I think. Take a look at this addon, maybe it will help
storybook.js.org/addons/msw-storyb...
Thanks for your response, Andrew. I will take a look. Without Nx in the picture, I have never had to do anything more than starting MSW from
.storybook/preview.tsx. For example, in this repo I have the same app working with CRA and Storybook and everything works just fine!!!