oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.03k stars 2.66k forks source link

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

Open ynhhoJ opened 2 months ago

ynhhoJ commented 2 months ago

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](https://github.com/withastro/astro/assets/22500212/77b73697-a23a-426c-864c-612ed54c5f74)

Additional information

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

bholmesdev commented 1 month ago

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?

ynhhoJ commented 1 month ago

@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.

bholmesdev commented 1 month ago

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!