msw-storybook-addon: Breaks on building Storybook
While building the Storybook, the bundler (Vite) emits an error like this:
[commonjs--resolver] No known conditions for "./native" specifier in "msw" package
This is because of the code here. While it’ll work without any problem when not built, this will break on browser builds because…
- The bundler doesn’t know whether
IS_REACT_NATIVEis true or false at build time, therefore it should try to bundle both versions. - However, since the bundler is building for browsers and that enables the
browserexport condition, the entry resolves to null and it errors.
This problem should be fixed by adding separate entries for each browser and native.
About this issue
- Original URL
- State: closed
- Created 6 months ago
- Reactions: 24
- Comments: 18
Hey everyone! If you’re using MSW 2.0.0, we just released a new beta version that should have fixed this issue:
msw-storybook-addon@2.0.0-beta.1.Would you please try it out and let us know? Thank you! cc @satoshi-izawa @marksulls tagging you since I know you’re using msw 2!
Fixed by fixing the dep version in package.json
for those using
vite, I was able to fix thenot found ./native moduleby adding this tovite.configHey everyone! Finally the major version is out. Sorry for such a long wait, I had to make sure the addon aligned with Storybook 8 and worked correctly in the portable stories (using stories in Vitest,Jest) scenario.
Please check the release notes, try it out and provide feedback in case issues arise: https://github.com/mswjs/msw-storybook-addon/releases/tag/v2.0.0
Thanks!
The types aren’t correct for the
2.0.0-beta1but everything else works otherwise!For those who try it out, be very careful with your version specification in package.json. There’s a “next” version of 2.0.0,
2.0.0-next.1, that is 9 months old – but e.g. a version pin of>= 2.0.0-beta.1will select that one. I suggest double checking your lockfile to see exactly what version you end up with.worked for me: //vite.config.ts
I faced the same problem
node_modules/vite/node_modules/esbuild/lib/main.js:1374:21: ERROR: [plugin: vite:dep-pre-bundle] No known conditions for "./native" specifier in "msw" packagemsw-storybook-addon:
2.0.0-beta.0msw:2.0.13vite:5.0.11