ReferenceError process is not defined
I am trying to use UploadThing together with a Cloudflare Worker and tiny-request-router. Currently when I send a POST request with a png file attached via Insomnia to my "api/uploadthing" endpoint, I receive the following error "ReferenceError process is not defined". Here is what my "index.ts file looks like:
Here is what my "wrangler.toml" file looks like:
And this is my "types.ts" file:
6 Replies
process
is not defined so process.env.UPLOADTHING_SECRET ??= env.UPLOADTHING_SECRET;
is expected to fail.how and where should I define process?
Move
createServerHandler
into your fetch
handler and pass a config
object containing uploadthingId
and uploadthingSecret
instead.
https://github.com/pingdotgg/uploadthing/blob/dbbfceec704dc156ce2b5ba6fa383856c83f3e51/packages/uploadthing/src/internal/handler.ts#L84-L91
Unless you're happy to use define
to do build-time constants, your import * as process from 'node:process';
isn't going to also import process
for UploadThing's code.
You could try globalThis.process.env.UPLOADTHING_SECRET ??= env.UPLOADTHING_SECRET;
as an alternative, to make sure that it's a global.If I do it like this, then I won't get the "ReferenceError: process is not defined" error anymore, but instead I get a "400 bad request" and this JSON response:
{
"message": "No slug provided"
}
@kian thanks for your help I have solved it now!