-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always 404 error returns on next.js environment #119
Comments
workaround is I added the below code in my component
|
Having the same issue, thank you @hiromaily for the workaround. |
Actually, it would be better to be able to have different handlers for different stories. |
I've found a better solution, I'm now using mswDecorator instead of mswLoader. and it's working fine. |
can you share with us how you configuration looks like? I'm having the same problem :( |
Hi! const preview: Preview = {
decorators: [ mswDecorator ]
} |
Thank you, it worked for me. Now I'm having a problem with MSW and Vitest (not related to the storybook stuff) but that's a problem for the me of the future :) |
I'm encountering the same problem and nothing I do seems to work. My stack:
I tried skipping the addon completely and initializing MSW with a debug handler manually. import { graphql, rest, setupWorker } from 'msw';
loaders: [
async () => {
const worker = setupWorker(
...[
rest.get('/test', (req, res, ctx) => {
console.log('REST');
return res(ctx.status(200), ctx.json({ foo: 'bar' }));
}),
graphql.operation((req, res, ctx) => {
console.log('GQL');
return res(ctx.data({ foo: 'bar' }));
}),
],
);
await worker.start({
serviceWorker: {
url: '/mockServiceWorker.js',
},
onUnhandledRequest(request, print) {
// Ignore any requests containing "cdn.com" in their URL.
if (!request.url.href.includes('graphql')) {
return;
}
console.debug(worker);
// Otherwise, print an unhandled request warning.
print.warning();
},
});
},
], The worker does seem to have the handlers registered correctly I do get the following response for the REST handler:
Seems to point to this line of code. Could there be something wrong? Edit: if I dig a little deeper, it seems to point to this commit in the headers-polyfill version 3.3.0 package where Workaround: Setting the package resolution in "resolutions": {
"headers-polyfill": "3.2.5"
} |
Though I set handler that handler doesn't work and 404 error returns.
I made sure logging
[MSW] Mocking enabled.
on console.I set various handler, get method, post method, full path url, relative path url, handler on preview.ts, handler on each component, but it doesn't change anything.
when I set
onUnhandledRequest
event, this event always emits.Is that because next.js specific issue?
I called
getWorker()
on my storybook component, but its datacurrentHandlers: Array(0)
expresses no handlers set.my preview.ts is
dependency
The text was updated successfully, but these errors were encountered: