remix-run / remix

Build Better Websites. Create modern, resilient user experiences with web fundamentals.
https://remix.run
MIT License
30.1k stars 2.55k forks source link

Cloudflare deploys crashing for Remix Vite when using `import { createCookie } from "@remix-run/cloudflare";` #8992

Open alvarp opened 8 months ago

alvarp commented 8 months ago

Reproduction

Github Repo with isolated repro: https://github.com/alvarp/remix-vite-cloudflare-auth-repro

Running npm run deploy in this project will result in a broken deploy. The wrangler cli reports that the deploy is successful but the Cloudflare dashboard shows This deployment failed without any other info.

Just commenting the usage of the auth helpers in the line 15 of the index route will result in a fully successful deploy, meaning that the issue comes from the createCookie method.

Please let me know if I should expand something for an easier reproduction, happy to help!

System Info

The wrangler cli reports a successful deploy:

> wrangler pages deploy ./build/client

✨ Compiled Worker successfully
🌍  Uploading... (7/7)

✨ Success! Uploaded 0 files (7 already uploaded) (0.23 sec)

✨ Uploading Functions bundle
✨ Deployment complete! Take a peek over at https://***.***.pages.dev


### Used Package Manager

pnpm

### Expected Behavior

The deploy should work as long as the remix-run dependencies are the ones specific for Cloudflare.

### Actual Behavior

The Cloudflare dashboard shows a failed deployment.
mw10013 commented 8 months ago

https://github.com/mw10013/remix-vite-cloudflare-auth-repro/blob/b30db7343c8c2ff4ce66ef64c2d1442082a3e45c/app/auth/auth.ts#L7

const secret = process.env.COOKIE_SECRET || "default";

Cloudflare runtime does not have process.env so you'll need to follow the Cloudflare way for environment variables: https://developers.cloudflare.com/workers/configuration/environment-variables/

Since it's a secret, you may want to put it in .dev.vars locally. And you'll also need to define it using the Pages dashboard when you deploy.

I put together the cloudflare example (https://github.com/mw10013/remix-auth-totp-cloudflare-example) for remix-auth-totp. It may be helpful to see one way of approaching environment variables in remix with cloudflare though it drags in KV and D1 so may be a bit noisy.

alvarp commented 8 months ago

@mw10013 Thank you for your reply. I'll check if updating the env-var reference fixes this.