Skip to content
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

Clean install is weirdly borked #232

Closed
JamesYeoman opened this issue Feb 9, 2022 · 5 comments · Fixed by #262
Closed

Clean install is weirdly borked #232

JamesYeoman opened this issue Feb 9, 2022 · 5 comments · Fixed by #262

Comments

@JamesYeoman
Copy link

So I used npx sb@next repro, and it all works fine. But as I've commented in the following code block, a clean vite + sb-builder-vite install errors out

yarn create vite # I used the react-ts template
cd <folder name>
yarn
npx sb@next init --builder storybook-builder-vite # https://storybook.js.org/blog/storybook-for-vite/
yarn storybook # acorn jsx error
yarn add --dev @storybook/core-common webpack@^5 # Peer dependencies that yarn said were unmet, so this is an attempt to try to fix the error
yarn storybook # acorn jsx error still occuring

Here's a screenshot of the "acorn jsx error"
image

This error seems to make everything load infinitely. No error gets displayed in my shell, and everything comes to a standstill.

@joshwooding
Copy link
Member

I think this happens when two incompatible versions of acorn are used. I'll see if I can reproduce

@JamesYeoman
Copy link
Author

Here's a repo with the reproduction up to the first yarn storybook https://github.com/JamesYeoman/sb-vite-bug-repro if it helps. I'm also using node v16.10.0 and yarn v1.22.17, all installed using volta on Windows 10

@wayne-o
Copy link

wayne-o commented Feb 25, 2022

I am getting this on a clean install - bit of a blocker :/

@IanVS
Copy link
Member

IanVS commented Feb 25, 2022

OK, thanks for the reproduction @JamesYeoman. I've figured out what's happening. If acorn-jsx is not hoisted up to the top-level node_modules directory, it isn't being pre-bundled (see vitejs/vite#3024), and for whatever reason (probably changes to the dependencies used inside storybook), acorn-jsx is now only inside node_modules/@storybook/addon-docs/node_modules/acorn-jsx, so it isn't being processed/pre-bundled.

The temporary solution is to add '@storybook/addon-docs > acorn-jsx' to your optimizeDeps.include in viteFinal (being careful not to overwrite the existing values in the config). I'm working on adding it to our base config, but this is tricky to do with this > syntax. I think I've found a way, though, and should have a PR up shortly.

@IanVS
Copy link
Member

IanVS commented Feb 25, 2022

Oh, and you'll probably also hit storybookjs/storybook#17516 next. I've got a PR up in storybook to fix it, but for now you can remove addon-interactions.

IanVS added a commit that referenced this issue Feb 25, 2022
Fixes #232 

This tweaks the way we do our `optimizeDeps.include` slightly, allowing us to add `'@storybook/addon-docs > acorn-jsx'`.  I needed to change our `filter` function to use the resolution that vite does (see https://github.com/vitejs/vite/blob/67d164392e8e9081dc3f0338c4b4b8eea6c5f7da/packages/vite/src/node/optimizer/index.ts#L182-L199), but in the end I think this is more reliable than what we were doing before, anyway.  

With this syntax in place, we might also be able to avoid optimizing the storybook deps themselves, like `@storybook/addon-docs`, which already has an ESM export and doesn't really need to be pre-bundled at all, only its sub-dependencies do.  I haven't changed anything like that in this PR, though, since I wanted to take it one-step-at-a-time.  The only change made to the list itself is the addition of `'@storybook/addon-docs > acorn-jsx'`.

I also needed to prevent the vue alias from being added unless vue is actually being used, or else vite threw an error when I tried to resolve the config.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants