Comments (19)
@kettanaito - I'm having a similar issue using the latest versions of msw
(0.42.2
) and this addon (1.6.3
).
I'm seeing the mocking behaviour perfectly functional when running the development Storybook server, but when serving a static build through http-server
, it appears that the addon doesn't initialise at all. I can't see any errors to be able to show here either unfortunately.
The only thing I can think of that's different to the setup in the docs is that we're using the Storybook public folder instead of the regular app one, is it possible this could make a difference? The mockServiceWorker.js
file is correctly set up in .storybook/public/mockServiceWorker.js
.
"storybook": "start-storybook -s .storybook/public ./styles/images -p 6006",
Is there any more information I can provide for debugging purposes, or any advice on what could be incorrect in terms of configuration? Otherwise if confirmed, would it be possible to re-open this issue?
from msw-storybook-addon.
A colleague pointed out an unfortunate mistake to me, in that you can see above the build-storybook
command doesn't make use of -s .storybook/public
. Adding this made it work, which makes pretty obvious sense as to why the worker file wasn't in the build π€¦π» looks like I was only checking for the -s
flag in the serve command.
In any case, thanks for your responses, and for the work on this addon!
from msw-storybook-addon.
Hey, @pedrohba1. Thanks for raising this.
We've been working on the support of static Storybook builds for some time now, and it's already shipped in MSW. There's a remaining addon update and release to be issued, hopefully, this month, and you'll be able to use MSW with static builds just as you do during the regular dev builds. Please be patient. I'll update this issue once the new version of the addon is released.
from msw-storybook-addon.
@oanaOM we are currently working on improving the Storybook add-on, which will include the exact dependency versions to ensure static build support. If updating to [email protected]
didn't help, I recommend waiting for the next release of this add-on. Thanks.
from msw-storybook-addon.
@kettanaito - I'm having a similar issue using the latest versions of
msw
(0.42.2
) and this addon (1.6.3
).I'm seeing the mocking behaviour perfectly functional when running the development Storybook server, but when serving a static build through
http-server
, it appears that the addon doesn't initialise at all. I can't see any errors to be able to show here either unfortunately.The only thing I can think of that's different to the setup in the docs is that we're using the Storybook public folder instead of the regular app one, is it possible this could make a difference? The
mockServiceWorker.js
file is correctly set up in.storybook/public/mockServiceWorker.js
.
"storybook": "start-storybook -s .storybook/public ./styles/images -p 6006",
Is there any more information I can provide for debugging purposes, or any advice on what could be incorrect in terms of configuration? Otherwise if confirmed, would it be possible to re-open this issue?
Hey @tomcarter17 if you setup a repro repo I could take a look at it! But in terms of debugging, when providing statics via static dir in storybook, you should be able to access them via your-storybook-url.com/static-name, so try accessing your-storybook-url.com/mockServiceWorker.js and see if it resolves in the file or gives a 404
from msw-storybook-addon.
Great to know you figured that out @tomcarter17! I'd recommend using the new notation of staticDirs which would have avoided such issue in the first place, as it's shared between dev and build in Storybook!
from msw-storybook-addon.
Actually, as I discovered that we have a wildcard version range specified for the msw
peer dependency, as long as you install [email protected]
, you'll have a build support in Storybook, as 0.29.0 includes the fallback mode feature that enables such support.
Please update and let us know. Thanks.
from msw-storybook-addon.
Hi @kettanaito,
Thank you for the awesome library π
Could you point me to some docs or post here on how to set up msw
and msw-storybook
for a storybook static site?
from msw-storybook-addon.
Hey, @hyogman. Thank you for the kind words!
Static builds support is enabled by default since [email protected]
. As long as you've got that, or higher, version installed, your request handlers will work in static Storybook builds.
You can follow the MSW Storybook Add-on documentation to set the add-on in your Storybook project. There are no extra things necessary.
Note that static support affects static Storybook builds viewed under a file://
protocol (i.e. opening the built index.html
in your browser). When serving a build of any kind, MSW worked and works as expected.
from msw-storybook-addon.
Hey @hyogman and @kettanaito. I'm encountering the same issue: the mock service provider isn't being picked up at build time. Upgrading to [email protected]
didn't worked so was wondering if there is anything I need to look after?
from msw-storybook-addon.
@kettanaito ohh cool, thanks for letting me know! Do you know what is the timeline for the next release?
from msw-storybook-addon.
@kettanaito - I'm on [email protected]
and still unable to see this working. This would be great feature to have! Keep up the epic work.
from msw-storybook-addon.
@josh-biddick I'm using msw 0.35.0
it works under http-server
and also if you just open index.html
file in browser. However it doesn't work in JetBrais Rider built in server - but it's not big deal I guess.
from msw-storybook-addon.
Hey, @josh-biddick. Could you please share the exact error you're getting during the build? At this point, the static build support should be functional, so the issues you experience may be of a different nature. I'd like to learn more.
from msw-storybook-addon.
Thanks for the quick response @yannbf !
So I have managed to find an error now, that indicates the 404:
and also going directly to http://127.0.0.1:8080/mockServiceWorker.js
returns that direct 404. I'm happy to attempt an example repo but may take a little time. In the meantime happy to provide any additional help that'll be useful.
from msw-storybook-addon.
Looks like you're not serving the worker script. Make sure:
- You have generated the script via
npx msw init <PUBLIC_DIR>
; - You are using the
-s
flag for Storybook CLI to serve the public dir.
from msw-storybook-addon.
Unfortunately I've done both of those things. Inside the package scripts I have
"storybook": "start-storybook -s .storybook/public ./styles/images -p 6006", "build-storybook": "build-storybook",
so I did
npx msw init .storybook/public
yarn build-storybook
http-server <project dir>/storybook-static
and I'm still receiving the above π€
from msw-storybook-addon.
Great to know, thanks for this! We're currently at 6.3 so definitely a good reason to upgrade!
from msw-storybook-addon.
Happy to hear you've figured it out, @tomcarter17! π Yes, the -s
flag is the tricky one.
from msw-storybook-addon.
Related Issues (20)
- Problems with SB7: 404s on mocked calls and mockServiceWorker.js retrieval HOT 1
- Unable to customize default handlers in Story HOT 1
- Possible issue when used with build-storybook HOT 2
- [README.md] static dir should be indicated using `.storybook/main.js` instead of `-s` option HOT 3
- Storybook keeps reloading when this add-on is enabled HOT 2
- How to overwrite the handlers using the array definition? HOT 1
- Not catching API as expected HOT 2
- Can't get addon to work. Using react-query v4 and nextjs HOT 7
- Always 404 error returns on next.js environment HOT 8
- CanΒ΄t intialize msw on Sveltekit + Typescript HOT 1
- Support for MSW 2.0.0 HOT 25
- MSW 2.0 Support HOT 1
- Do not know how I can mock my RTK websocket with this lib HOT 3
- Can not able to import msw-storybook-addon HOT 1
- Breaks on building Storybook HOT 18
- Quick question on this library HOT 2
- Running msw-storybook-addon within test-storybook HOT 1
- codesandbox for using the addon HOT 1
- A livereload triggered by Webpack leaves the add-on in a bad state HOT 1
- Peer dependencies breaking install HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msw-storybook-addon.