Deployment Fails with @sveltejs/adapter-cloudflare
I am attempting to deploy to CloudFlare Page and I believe I need some help setting up my environment. My local environment is setup using Miniflare where I set the platform variable, here is what my
hooks.server.ts
file looks like:
I am using drizzle-orm and lucia-auth for this project. Here are some function definitions function getDB(db: D1Database) => DrizzleD1Database
and function getAuth(db: D1Database) => AuthRequest
(AuthRequest is a lucia type), however I don't think they are the issue, because it works just fine in my development environment with Miniflare.
Here is what my app.d.ts
file looks like:
When I build and attempt to deploy the build it says the event.platform
is undefined:
Deployment ID - 55b93723-6495-4000-bfb4-f3e971753c60
I have search Google for an answer to my problem, but I haven't been able to find anyone else who is having the same problem with platform being undefined in a SvelteKit hooks.server.ts
file. I have added the DB
, KV
and DOCS
bindings from the workers dashboard, however I don't think that is the problem as well, because the error shows that the event.platform
variable is undefined.
Hopefully I have enough information in this post. Any help is appreciated!5 Replies
The
event.platform
variable is for some reason undefined
. Even if I tried using the example provided here https://developers.cloudflare.com/d1/examples/d1-and-sveltekit/, I still run into a very similar problem, that platform
is undefined. Did you find any solutions yet @kdamp ?Yes, it is undefined only during your typescript build. It is defined in the Cloudflare runtime.
I don't know why, but that's just how it is
Thanks for the quick answer, it pointed in the right direction.
I found another post that discusses the issue of locally connecting to the database: https://discord.com/channels/595317990191398933/1126398478147407965/1126399469857026079
Basically, if I run this in one terminal
and this in another terminal
I suddenly gain access to envs, and can connect to a local database.
No problem. That is one way to do it! I personally set up a local Miniflare object and assigned that to the platform variable and that works for me. I get really annoyed when running two terminals at the same time lol
You can also run it like this
The
--
allows Cloudflare to make a proxy to the sveltekit port.thank you so much
i was dying