solidjs / solid-start

SolidStart, the Solid app framework
https://start.solidjs.com
MIT License
5.2k stars 375 forks source link

[Bug?]: Cloudflare Pages + Solid AuthJS build failure #1079

Closed austin-raey closed 11 months ago

austin-raey commented 1 year ago

Duplicates

Latest version

Current behavior 😯

When using the solid-start-cloudflare-pages in combination with @solid-auth/base or @solid-mediakit/auth, and deploying to Cloudflare Pages, the build will fail with the following error:

✨ Upload complete!
Success: Assets published!
Error: Failed to publish your Function. Got error: Uncaught ReferenceError: process is not defined   at functionsWorker-0.6340363868935264.js:8850:17

Expected behavior πŸ€”

Functions would successfully publish without a process undefined error.

Steps to reproduce πŸ•Ή

Steps:

  1. pnpm create solid choosing "with auth-js"
  2. Manually add solid-start-cloudflare-pages using the steps outlined here a. i.e. pnpm install solid-start-cloudflare pages, add plugins: [solid({ adapter: cloudflare({}) })] to vite.config.js.
  3. Go to CloudFlare, link the repo with the project produced by these steps and let it build. Ensure you choose dist/public as the build output directory.
  4. You will receive the process is not defined error.

Optionally after step 2, you may also replace @solid-js/auth with @solid-mediakit/auth and make relevant code updates to the generated project, noted here. Being that @solid-js/auth points to the other package, I assume @solid-mediakit/auth is the maintained version going forward.

This repo has everything configured with @solid-mediakit/auth.

Further, note that somewhere in the generated [[path]].js the following code:

function SolidAuth(config) {
    const { prefix = '/api/auth', ...authOptions } = config;
    authOptions.secret ??= process.env.AUTH_SECRET;
    authOptions.trustHost ??= !!(process.env.AUTH_TRUST_HOST ??
    ...

const authOpts = {
  providers: [
    GitHub({
      clientId: process.env.GITHUB_ID,
      clientSecret: process.env.GITHUB_SECRET
      ...

Context πŸ”¦

I was testing the waters with a few frameworks (Qwik, SvelteKit, SolidStart) for a particular stack combination I'm looking for:

SvelteKit and Qwik are able to deploy successfully to CloudFlare, however, solid's authjs package seems to exclusively use process to grab a few environment variables.

It seems to me this would need to be updated to safely check if process exists, and then probably use some Cloudflare specific global-type thing instead.

I'd love to open a PR / look into this for you guys, although I'm not sure where @solid-mediakit/auth is hosted. It would be awesome to open the door to another JAMStack provider like Cloudflare! solid-start also is one of the few out there that properly allow to do local development via Miniflare so you can actually have access to Cloudflare Bindings without needing to build / preview.

Your environment 🌎

`pnpm` 8, `node` 18, Cloudflare Pages
stickyburn commented 1 year ago

Is the project using SSR?

austin-raey commented 1 year ago

@stickyburn Apologies for the very late response,

Yes, I believe this is configured to use SSR in this example. Since the { ssr } option is not configured, I believe this means it defaults to true as noted here: https://start.solidjs.com/api/vite. πŸ˜„

stickyburn commented 1 year ago

Interesting. I asked because the same issue happens with client side rendering.

ryansolid commented 11 months ago

In setting up for SolidStart's next Beta Phase built on Nitro and Vinxi we are closing all PRs/Issues that will not be merged due to the system changing. If you feel your issue was closed by mistake. Feel free to re-open it after updating/testing against 0.4.x release. Thank you for your patience.

See https://github.com/solidjs/solid-start/pull/1139 for more details.