withastro / adapters

Home for Astro's core maintained adapters
47 stars 26 forks source link

QRCode Issues #233

Closed alexanderniebuhr closed 1 month ago

alexanderniebuhr commented 2 months ago

Describe the Bug

astro build doesn't work

What's the expected result?

astro build to work successfully

Link to Minimal Reproducible Example

https://github.com/mrthiti/astro-cloudflare-root-cause

Participation

alexanderniebuhr commented 2 months ago

This has a workaround, add the following to your astro config

  vite: {
    build: {
      rollupOptions: {
        external: ['qrcode'],
      }
    }
  },
bluwy commented 2 months ago

I think the issue is that when bundling for Cloudflare using ssr.target webworker, Vite will use the browser variant of the packages where possible as it's assumed that the browser-bundle is more likely to run compared to the node-bundle.

However, there's another problem here where the endpoint is getting prerendered, so technically we will run the code within node instead of workerd. I suppose this is another reason we need a secondary build for prerendering to be more robust.

I think the workaround you showed here is fine (setting ssr.external: ['qrcode'] also works too). But for a workaround within @astrojs/cloudflare, I'm not quite sure if it's possible at the moment.

alexanderniebuhr commented 2 months ago

I suppose this is another reason we need a secondary build for prerendering to be more robust.

@bluwy yeah, or at least to set different vite configurations for the different types. So that we can make sure on-demand rendered pages get the vite config which are needed for Cloudflare, while prerendered pages will keep the settings which work for node 🤔

alexanderniebuhr commented 1 month ago

This will be resolved, once upstream prerendering solution is more robust.