storybook: [Bug]: Fails to start using Vite v4.3 (esbuild error)
Describe the bug
With the latest Vite update (v4.3.1), Storybook (using v7.0.7) fails to build with the following error at the top of the logs:
[ERROR] Could not read from file: /path/to/node_modules/.cache/vite-plugin-externals/@storybook/core-events.js
Then after this there are lots of the following for many packages:
✘ [ERROR] Invalid command: on-resolve [plugin JavaScript plugins]
node_modules/vite/node_modules/esbuild/lib/main.js:745:12:
745 │ handleRequest(packet.id, packet.value);
╵ ^
at handleRequest (/path/to/node_modules/vite/node_modules/esbuild/lib/main.js:745:13)
at handleIncomingPacket (/path/to/node_modules/vite/node_modules/esbuild/lib/main.js:762:7)
at Socket.readFromStdout (/path/to/node_modules/vite/node_modules/esbuild/lib/main.js:690:7)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
The plugin "JavaScript plugins" was triggered by this import
node_modules/@storybook/blocks/dist/index.mjs:81:2422:
81 │ ...mposeConfigs}from"@storybook/preview-api";import{Channel}from"@storybook/channels";import{DocsContext as DocsContext2}from"@storybook/preview-...
Before updating to Vite v4.3.1 there were no issues with starting Storybook, and none of the config files have changed.
To Reproduce
No response
System
Environment Info:
System:
OS: macOS 13.2.1
CPU: (8) arm64 Apple M1
Binaries:
Node: 18.6.0 - /var/folders/vr/yrskg7qd5fbcj2kyy_8q52jc0000gn/T/yarn--1682465109348-0.43062969347345303/node
Yarn: 1.22.19 - /var/folders/vr/yrskg7qd5fbcj2kyy_8q52jc0000gn/T/yarn--1682465109348-0.43062969347345303/yarn
npm: 9.6.0 - ~/Library/Caches/fnm_multishells/91857_1682415868456/bin/npm
Browsers:
Chrome: 112.0.5615.137
Safari: 16.3
npmPackages:
@storybook/addon-a11y: ^7.0.7 => 7.0.7
@storybook/addon-essentials: ^7.0.7 => 7.0.7
@storybook/addon-interactions: ^7.0.7 => 7.0.7
@storybook/addon-links: ^7.0.7 => 7.0.7
@storybook/react: ^7.0.7 => 7.0.7
@storybook/react-vite: ^7.0.7 => 7.0.7
Additional context
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 38
- Comments: 71 (12 by maintainers)
Commits related to this issue
- Rollback vite to 4.2.2; 4.3 is breaking storybook, see: https://github.com/storybookjs/storybook/issues/22253 — committed to otterscan/otterscan by wmitsuda a year ago
- deps: bump deps 🌲 Could not bump vite to >4.3 due to this bug: https://github.com/storybookjs/storybook/issues/22253 — committed to agrc/deq-enviro by stdavis a year ago
- deps: bump deps 🌲 Could not bump vite to >4.3 due to this bug: https://github.com/storybookjs/storybook/issues/22253 — committed to agrc/deq-enviro by stdavis a year ago
- deps: bump deps 🌲 Could not bump vite to >4.3 due to this bug: https://github.com/storybookjs/storybook/issues/22253 — committed to agrc/deq-enviro by stdavis a year ago
- update vite and ignore .env (see https://github.com/storybookjs/storybook/issues/22253#issuecomment-1672438491) — committed to yasuaki640/images-management by yasuaki640 a year ago
- fix: fix storybook/vite errors Ref: https://github.com/storybookjs/storybook/issues/22253 — committed to agrc/kitchen-sink by stdavis 9 months ago
- fix: fix storybook/vite errors Ref: https://github.com/storybookjs/storybook/issues/22253 — committed to agrc/kitchen-sink by stdavis 9 months ago
npm up fsevents
worked for meGood news!
fsevents@2.3.3
has been released with the fix. Depending on your package manager, you should be able to<pkgmgr> up fsvents
(though watch out for pnpm, it may update other unrelated packages: https://github.com/pnpm/pnpm/issues/6657).I’ll close this out now, but please let us know if you continue to have issues with this.
I also notice my server restarting on
.env
changes, but they happen when no changes to the file are actually made. Is that what you experience as well? Or are you actually changing the contents of the file?That’s a good idea to ignore files that are causing problems, but keep in mind that you’ll need to manually restart if you do change a
.env
file, of course.Same issue for me. My storybook keeps flickering and lots of terminal messages with
The plugin "JavaScript plugins" was triggered by this import
coming through. We’re doing conversion from webpack 4 to vite and Storybook 6 to 7. Can’t really complete it until storybook is working.Update: I also see this error at the top of my terminal,
[vite] Internal server error: Cannot set properties of undefined (setting 'isSelfAccepting')
. Indicating theres some issue with vite.@IanVS thank you for the investigation! in the console im getting reports for so many imports which im not getting on
vite dev
orpreview
orbuild
… only on storybookEDIT: BTW, it’s not happening on vite 4.2.3
just upgraded to vite
4.3.8
which includes this fix and still having the blinking issue@jfairley Thanks for the tips, I noticed the server was restarting on .env changes:
By adding this in
./storybook/main.ts
, it seems to fix the issue (at least for now):Downgrading Vite to v4.1.5 is required in my case
I had the same issue when migrated the project from webpack/vue2 to vite/vue3. This command fixed the issue in my case:
I found it here: https://www.npmjs.com/package/@storybook/builder-vite#migration-from-webpack--cra I hope it helps someone too 😃
Tried to debug it a little in some setup I have and it looks to me like this is the cause: https://github.com/paulmillr/chokidar/issues/1286
@woodreamz ignoring .env is a brilliant workaround. Vite doesn’t restart in a loop anymore, was able run vite@4.4.9 (latest atm) and storybook@7.2.2 (latest atm)
Full
.storybook/main.ts
below:I don’t know whether this is related, but I had to boot a couple plugins to make my storybook work.
in
.storybook/main.ts
:IIRC…
vite-plugin-checker
is unquestionably the one plugin I use that just prevents storybook from ever startingvite:dts
(vite-plugin-dts
) doesn’t prevent storybook from running but yarfs warningsAnother tweak I have (unrelated to storybook) is in
vite.config.ts
.vite optimize
doesn’t likevite-plugin-checker
(hencemode === "production"
)vite-plugin-checker
.The lesson is just comment out your plugins one at a time and see if you make progress. YMMV
I am still seeing issues with Vite v4.4.4 and Storybook v7.1. Is anyone else still having issues? Or is there some fix available?
This is the error in the terminal after starting storybook:
Error: The server is being restarted or closed. Request is outdated
This is the error in the browser console:
GET http://localhost:9009/sb-preview/runtime.js net::ERR_ABORTED 404 (Not Found)
I’ve downgraded vite from
4.3.9
to4.1.4
and now storybook@7.0.18 works.ref: https://github.com/storybookjs/storybook/issues/22808#issue-1726935613
@eifr-vault ah, yeah I see those in the reproduction from @ryota-murakami as well. I’ll see if I can figure out what’s causing those.
I’m also seeing this behavior after updating from webpack 5 + Babel to Vite + react-swc and Storybook 6 -> 7.
Invalid command: on-resolve [plugin JavaScript plugins]
The error gets triggered by all sorts of imports in the app, its dependencies and Storybook itself
Deleting node_modules and reinstalling it with yarn solve it.
Still seeing this w/ Storybook 7.2
sudo pnpm dev
resolve this. but why?as @craftgear mentioned, In my case I had to downgrade even more to vite@4.1.4
I’m getting this error with @radix-ui/react-use-previous:
I tried clearing the cache, updating vite, restarting storybook etc. But nothing is working for me.
on vite; 4.3.9 and storybook: 7.0.20
I’m seeing the same issue, trying to isolate it.
I figured out that it occurs on vite 4.3.0, but not in 4.2.2 (latest from 4.2 series).
Could someone confirm it?
One thing that consistently (but not permanently) fixes this issue for me:
And now it works 🤯
If I repeat the cycle, the first
npm run storybook
fails again, but the second one (after runningnpm update vite
) works.The Vite version in my
package-lock.json
is also unchanged (4.3.5) after I runnpm update vite
Ps.
# [output suppressed]
messages added by myself for brevityI get a simliar problem but with react-syntax-highlighter.
Confirming that manually patching
fsevents
fixes this issue on Machttps://github.com/fsevents/fsevents/commit/63709df0fd91549050e2e3f38b1695f49f6387a8
Same issue here, but then not with the storybooks. I’m using NX however, and it keeps restarting due to file changes that really did not happen.
When downgrading to Vite 4.1.4 it indeed seems solved. However it does really suck, and should be an issue
ignoring
env
did fix some of the issues but I’m still getting this ^vite.config
:@IanVS Ah yes, definitely, I should’ve mentioned that too. My storybook was also looping due to supposed changes to my .env files, though I had not changed them at all. That is why I added the
server.watch.ignored
section.Edit: I have the
**/coverage/**
part because I’m using@storybook/test-runner
, and writes to coverage also cause restarts.Deleting the
node_modules/.cache
directory only sometimes helped me. The wierdest thing is, that everything is fine and suddenly this error occures on another day when starting the dev mode.In our case, we use a monorepo with several workspaces with yarn. We also made an exception how vite is linked within the yarn config.
@woodreamz, I’ve hit the issue occasionally before, and it seems to be intermittent. If I clear my node_modules and re-install, it usually resolves. I imagine that’s likely what happened to you. I don’t think there’s any actual change between SB 7.1.1 and 7.2 that would have made a difference in this issue.
I think it happens when Vite restarts during optimizeDeps, one thing that triggered this for me was vitejs/vite#13505
I’ve talked to the Vite folks, and they don’t really know what’s causing this either. As far as I know, it’s not an issue with Storybook specifically, but I can’t say for sure. Ideally we would find some way to reproduce this without Storybook to help Vite/esbuild troubleshoot the problem.
Do we have an idea on the solution? This issue seems to be there since few versions, it’S still there in storybook 7.2.0 and vite 4.4.8.
I’ve upgraded Storybook to the latest v7.1.1 version and it seems to work for me with Vite v4.3.9.
reverting back to
vite 4.1.4
solved that for me@jfairley that is true in storybook 6.5, which is what the repo you found is used in, but in Storybook 7.0+, the vite config is read and used.
I think the trigger in our case was https://github.com/vitejs/vite/issues/13505
I’ve had this occur once in a while too now. I’m hopeful that vite 4.4 may fix it. In the meantime, clearing the cache and restarting storybook seems to work for me.
It seems like this might be related to an issue in Vite/esbuild that occurs when a build is cancelled and then restarted in a short time. If anyone is able to reproduce it without using Storybook, it would be great to submit the issue to Vite.
Potentially similar issues, that also mention React Syntax Highlighter (@arlukin):
I’d like to stress that my project does not use React Syntax Highlighter though
I’m getting the same issue with Chakra UI:
I’m unable to run a reproduction on Stackblitz with the same project setup unfortunately. I’ve tried to debug why, but I was unable to reach a conclusion. I still hope this adds some information though in order to find the root cause