bun icon indicating copy to clipboard operation
bun copied to clipboard

Bun + Astro (Vite): Unexpected end of JSON input when using actions

Open ynhhoJ opened this issue 1 year ago • 2 comments

What version of Bun is running?

1.1.18+5a0b93523

What platform is your computer?

Linux 6.9.6-200.fc40.x86_64 x86_64 unknown

What steps can reproduce the bug?

  1. Download Stackblitz example: https://stackblitz.com/edit/withastro-astro-pdghi3?file=src%2Fcomponents%2FLike.tsx
  2. Use bun i
  3. Run project with bun run --bun dev
  4. Access localhost:4321
  5. Click on button near Will return: Error: Unable to get API context.
  6. Error

What is the expected behavior?

There is no Unexpected end of JSON input error and is returned an actual response (77)

npm run dev: image

What do you see instead?

Image

image

Additional information

https://github.com/withastro/astro/issues/11423

ynhhoJ avatar Jul 08 '24 17:07 ynhhoJ

I confirmed this issue occurs with the --bun flag, but goes away when running bun run dev. I'm not super familiar with the difference, but it sounds like bun switches back to node.js for Vite projects when --bun is omitted?

bholmesdev avatar Jul 12 '24 11:07 bholmesdev

@bholmesdev , https://bun.sh/docs/cli/run#bun :

By default, Bun respects this shebang and executes the script with node. However, you can override this behavior with the --bun flag. For Node.js-based CLIs, this will run the CLI with Bun instead of Node.js.

ynhhoJ avatar Jul 12 '24 14:07 ynhhoJ

Update: we've found this issue is actually related to request.clone() dropping the response body. We see this is being tracked separately by Bun: https://github.com/oven-sh/bun/issues/6348

Should be safe to close this PR as a duplicate. Hope Bun can prioritize a fix on this!

bholmesdev avatar Aug 02 '24 11:08 bholmesdev