Skip to content
Init is coming / May 19 - 23
Back

JSON Parse error: Unexpected EOF when executing from console

  • 0
  • Functions
  • Cloud
razor
18 May, 2025, 03:46

Hi, I'm trying to test a piece of code and I can't figure out what I'm doing wrong. I've reduced the deployed main to just this

TypeScript
export default async ({ req, res, log, error }: any) => {
  log(Date.now())
  log(JSON.stringify(req, null, 2))
}

to debug. I'm trying to run an execution from the web console. Ive tried:

  • setting/unsetting the content-type: application/json header
  • body: {}, "{}", {"actual": "json"}, '{"actual": "json"}', some text, "some text"

But no matter what, I get this in the error console

TypeScript
SyntaxError: JSON Parse error: Unexpected EOF
    at <parse> (:0)
    at parse (native)
    at stringify (native)
    at <anonymous> (/usr/local/server/src/function/src/main.ts:7:12)
    at starDefault (/usr/local/server/src/function/src/main.ts:5:16)
    at <anonymous> (/usr/local/server/src/server.ts:172:20)
    at processTicksAndRejections (:12:39)

I'm using Bun1.1 as the runtime.

TL;DR
Developers are experiencing a JSON Parse error with the Bun1.1 runtime when executing from the console. The issue might be alternative runtime support. Solutions include porting to Node or ensuring a proper response is being returned at the end of the function. Finally, despite various test methods, the error persists, so further debugging is necessary.
Steven
18 May, 2025, 04:07

you need to return a response

razor
18 May, 2025, 04:12

Same thing

TypeScript
export default async ({ req, res, log, error }: any) => {
  log(Date.now())
  log(JSON.stringify(req, null, 2))
  return res.empty()
}
razor
18 May, 2025, 04:16

If i just log(req) then I get

TypeScript
SyntaxError: JSON Parse error: Unexpected EOF
    at <parse> (:0)
    at parse (native)
    at stringify (native)
    at write (/usr/local/server/src/logger.ts:61:27)
    at log (/usr/local/server/src/server.ts:145:14)
    at <anonymous> (/usr/local/server/src/function/src/main.ts:7:3)
    at starDefault (/usr/local/server/src/function/src/main.ts:5:16)
    at <anonymous> (/usr/local/server/src/server.ts:172:20)
    at processTicksAndRejections (:12:39)
razor
18 May, 2025, 04:26

Okay some more info: Deploying the same code with node22 works as expected. Trying to then switch this over to Bun gives me an error that npm is not installed

razor
18 May, 2025, 04:26

Sounds like the issue is with the Bun1.1 runtime, I'll try porting to node later to see if that fixes things, but the support for Bun is one of the main reasons I switched from supabase

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more