-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[Bug]: Overwriting "build" object in vite config in build mode prevents use of top-level await #22223
Comments
Using viteFinal works as a workaround. However, I still think this should be considered as a bug since it breaks expectations. I think it is sensible to expect this to work from one place instead of needing to readd it just for storybook.
|
It looks like this is intentional according to this comment storybook/code/builders/builder-vite/src/vite-config.ts Lines 47 to 49 in 93d7993
BUT I really think at least target option should be allowed to pass. It does not break storybook build, or if it did break there is something else wrong. |
For anyone else stuck on this there are actually two places you need to set the In your vite config you'll want the following export default defineConfig({
optimizeDeps: {
esbuildOptions: {
target: "esnext",
},
},
build: {
target: "esnext",
},
}) In your storybook const config: StorybookConfig = {
viteFinal: (viteConfig) =>
mergeConfig(viteConfig, {
build: {
target: "esnext",
},
}),
}; |
The PR, which introduced this, states it was a conscious decision not to take over the user's |
We just stumbled upon this bug when integrating originjs/vite-plugin-federation which requires top-level await support. The current behaviour of silently overriding the setting and failing is far from ideal DX. At the very least it should detect if that setting is defined in user's vite config and warn with possible workaround |
Describe the bug
I have the need to use a toplevel await in 2 places. The current way to support this with vite and prevent the following error is to add:
to the config. However the code of storybook deletes this on builds.
The error you get in vite with top-level awaits is:
For reference: vitejs/vite#6985
To Reproduce
Any storybook is fine as long you got a top-level await anywhere in the code and use vitejs to build it.
System
Additional context
The code causing the issue are these lines
storybook/code/lib/builder-vite/src/build.ts
Lines 13 to 17 in 7b2e1a7
build
The text was updated successfully, but these errors were encountered: