-
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
Help when building storybook and deploying on Vercel #136
Comments
I'm also having same exact issue when deploying to GitLab pages. Everything works when I build locally and run through http server, or the live server plugin in VsCode. I can download the build file from the pipeline, and run it the same way. The page will deploy but won't find the MockServiceWorker.js. Never had issues with storybook 6.5 and this plugin. But we upgraded to sb7 and now can't get this to deploy properly. |
also, my Vite has a base url, that might be causing issue. www.example.com/mockServiceWorker.js will show mock service worker route, but www.example.com/my-app/mockServiceWorker.js wont. @alexbjorlig do you have something like this in your vite.config setup? |
adding this to
https://storybook.js.org/docs/7.4/configure/images-and-assets I believe you can also do this in
Hope that helps! |
Hi @jimsheen , I troed adding
|
@alexbjorlig What version of Storybook are you running? webpack or vite? |
vite
|
Yeah, it works, but then it breaks custom fonts to work. We have the following setup derived from this issue: staticDirs: [
{
from: "../public",
to: "/public",
},
{ from: "../public/fonts", to: "/fonts" },
], With this, Storybook is unable to find the So, let's try: staticDirs: [
"../public",
{ from: "../public/fonts", to: "/fonts" },
], It does not work. If we use What can we do here? Storybook Environment Info:
System:
OS: Linux 6.1 Manjaro Linux
CPU: (16) x64 AMD Ryzen 9 5900HX with Radeon Graphics
Shell: 5.2.26 - /bin/bash
Binaries:
Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
Yarn: 1.22.21 - /usr/bin/yarn
npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
pnpm: 8.15.4 - /usr/bin/pnpm <----- active
npmPackages:
@storybook/addon-a11y: 7.6.17 => 7.6.17
@storybook/addon-essentials: 7.6.17 => 7.6.17
@storybook/addon-interactions: 7.6.17 => 7.6.17
@storybook/addon-links: 7.6.17 => 7.6.17
@storybook/addon-onboarding: 1.0.11 => 1.0.11
@storybook/addon-storysource: 7.6.17 => 7.6.17
@storybook/addon-themes: 7.6.17 => 7.6.17
@storybook/blocks: 7.6.17 => 7.6.17
@storybook/nextjs: 7.6.17 => 7.6.17
@storybook/react: 7.6.17 => 7.6.17
@storybook/test: 8.0.0-alpha.16 => 8.0.0-alpha.16
@storybook/theming: 7.6.17 => 7.6.17
eslint-plugin-storybook: 0.8.0 => 0.8.0
msw-storybook-addon: 2.0.0-beta.1 => 2.0.0-beta.1
storybook: 7.6.17 => 7.6.17
storybook-addon-pseudo-states: 2.1.2 => 2.1.2
storybook-addon-rtl: 1.0.0 => 1.0.0
|
@alexbjorlig staticDirs: [
{
from: "../public",
to: "/",
},
{ from: "../public/fonts", to: "fonts" },
], This addon always looks the mock on the URL root. I tried following this thread: initialize({
onUnhandledRequest: "warn",
serviceWorker: {
url: "/public/mockServiceWorker.js",
},
}); It enables the mock but doesn't intercept any request:
|
Haven't tried for Vercel but I was getting the same issue in my Docker container. The following setup helped. // preview.tsx
initialize({
serviceWorker: {
url: './mockServiceWorker.js',
},
}); // main.ts
staticDirs: [
{ from: '../public', to: 'public' },
{ from: '../public/mockServiceWorker.js', to: 'mockServiceWorker.js' },
{ from: '../assets/fonts', to: 'assets/fonts' }, // Local fonts
], |
Hey there! I actually publish a Storybook for a personal project in both Vercel and Netlify and I have no issues with MSW there. First of all, you need to make sure MSW is available via staticDirs in Storybook's config: import { StorybookConfig } from '@storybook/react-vite'
const config: StorybookConfig = {
// ...
staticDirs: ['../public'], // this must match where your MSW file is at
}
export default config VercelI deploy the app in https://mealdrop.vercel.app and Storybook in https://mealdrop.vercel.app/storybook, and the configuration I use is: // ./vercel.json
{
"redirects": [
{
"source": "/storybook",
"destination": "/storybook/"
}
],
"rewrites": [
{
"source": "/storybook",
"destination": "/storybook"
},
{
"source": "/(.*)",
"destination": "/"
}
],
"github": {
"silent": true
}
} NetlifyI deploy the app in https://mealdrop.netlify.app and Storybook in https://mealdrop.netlify.app/storybook, and the configuration I use is: // ./public/_redirects
/storybook /storybook 200
/* /index.html 200 |
I'm pretty new to Storybook, and hope you can help me out here.
I have
msw-storybook-addon
installed version1.10.0
, working fine running locally on my machine.When I try to build the storybook with the
storybook build
command, everything also seems to work on Vercel. However, when I visit the environment I get this error:I tried adding
But that did not seem to help.
On Vercel I'm using the Storybook framework preset, that lists
storybook-static
as "Output directory".What is wrong with the above configuration 🧐?
The text was updated successfully, but these errors were encountered: