withastro / adapters

Home for Astro's core maintained adapters
46 stars 25 forks source link

Cloudflare build fails when using experimental env vars (rollup failed to resolve import "astro:env/client") #306

Closed jkhaui closed 2 days ago

jkhaui commented 1 week ago

Astro Info

Astro                    v4.11.1
Node                     v20.6.1
System                   Windows (x64)
Package Manager          unknown
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             my-astro-integration
                         @qwikdev/astro
                         astro-react-navigation
                         @astrojs/tailwind
                         @astrojs/sitemap
                         @playform/compress

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Hi,

I saw the cloudflare adapter had a major update, so I read the changelog and noticed there appears to be a push to use the experimental env vars option. So I've followed the instructions and my dev environment works fine.

But when deploying to CF, I get the following error about rollup failing to resolve astro:env/client:

image

Then, I follow the workaround to externalise it, and now I get this error:

image

No idea what to do - is this a Cloudflare issue, an actual bug, or am I just overlooking something really obvious? Btw, I know the Astro team is great and works hard to support many runtimes, use-cases, etc. but boy I've probably spent more time trying to get project configuration & environment variables working in dev vs. prod than actually developing my app

What's the expected result?

Env vars should work in production

Sorry for not providing a proper repo, it's just not feasible considering we're dealing with a CF build pipeline issue

Link to Minimal Reproducible Example

https://stackblitz.com/github/withastro/astro/tree/latest/examples/basics?file=README.md

Participation

bluwy commented 1 week ago

Are you using the latest version of @astrojs/cloudflare? It should be fixed now. There was an unintended breaking change that required installing the latest version of Astro as well (which you could also do to workaround the problem if you can't upgrade @astrojs/cloudflare)

jkhaui commented 1 week ago

Are you using the latest version of @astrojs/cloudflare? It should be fixed now. There was an unintended breaking change that required installing the latest version of Astro as well (which you could also do to workaround the problem if you can't upgrade @astrojs/cloudflare)

Hey Bjorn, appreciate the quick reply. Yep I am using the latest cloudflare adapter & astro versions (11.0.1 & 4.11.1 respectively)

jkhaui commented 1 week ago

Oh and another thing I realised - for my project, bumping the cloudflare adapter version to 11+ completely breaks my prod build (after I replace all the env vars with hardcoded strings to unblock myself on the issue opened here).

Below you can see the background gradient on the body being rendered, but none of the islands (or even static HTML components for that matter) render:

image

Interesting how the browser console is also free of error messages. I'm pretty certain it's the major version bump for the CF adapter causing this as I push regularly (daily) and only finding these problems now. And updating to the latest Astro version in isolation doesn't break anything

I'll check the CF server logs and update if I find any important info, just let me know if I can provide anything else that will help you - cheers

update: Ok, confirming a couple of findings:

  1. Reverting to @astrojs/cloudflare 10.4.2 completely resolves this rendering issue
  2. Here's the exception message from my CF worker runtime logs (when I was using 11.0.1): image

For now I will use these workarounds and avoid using v11+ of the adapter so hopefully you have more time to rectify the root cause

bluwy commented 1 week ago

Since this is related to @astrojs/cloudflare, I'll move this over to the adapter repo. However, it would be great if you can provide a repro, or perhaps @alexanderniebuhr has a hint of the issue.

florian-lefebvre commented 1 week ago

I wish I could help on that one for astro:env but i know very little about how cloudflare works so i'll wait for Alex's opinion first

alexanderniebuhr commented 1 week ago

@jkhaui can you provide a reproduction? You can also provide your project, so I can take a look to see if that is enough.

alexanderniebuhr commented 2 days ago

Happy to reopen this issue, when a reproduction is provided.