Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Astro + Svelte + Cloudflare] Cannot build Svelte component that contains $onMount() with Cloudflare adapter #485

Closed
1 task
GoodLucky777 opened this issue Dec 15, 2024 · 4 comments

Comments

@GoodLucky777
Copy link

GoodLucky777 commented Dec 15, 2024

Astro Info

Astro                    v5.0.5
Node                     v18.20.3
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/svelte

Describe the Bug

If I try to build the Astro website that contains Svelte component with $onMount() and Cloudflare adapter, the build error will occurs like this.

Build error:

$ npm run build

prerendering static routes 
01:36:03 ▶ src/pages/index.astro
01:36:03   └─ /index.htmlhttps://svelte.dev/e/lifecycle_outside_component
  Stack trace:
    at lifecycle_outside_component (file:///home/projects/github-memgm1vc/dist/_worker.js/pages/index.astro.mjs?time=1734280563043:32:9)
    at Test (file:///home/projects/github-memgm1vc/dist/_worker.js/pages/index.astro.mjs?time=1734280563043:69:9)
    at renderToStaticMarkup (file:///home/projects/github-memgm1vc/dist/_worker.js/chunks/_@astro-renderers_BFYr5CxZ.mjs:1251:23)

It doesn't occurs when I use NodeJS adapter. It seems it is occurring after @astrojs/cloudflare@12.1.0 update.

What's the expected result?

No build errors.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/astro-svelte-cloudflare-build-error

Participation

  • I am willing to submit a pull request for this issue.
@rognstadragnar
Copy link

Seeing the same thing. It also fails when using setContext with the same error message.

Previously this error was caused because the Vite resolve conditions were including node. A related issue when using Vue was attempted fixed in #476 and released in the latest @astrojs/cloudflare@12.1.0.

Unfortunately this did not fix the Svelte issue, as it introduced the browser resolve condition for the server environment. This now leads Svelte to pick its browser version when running on the server.

@bluwy
Copy link
Member

bluwy commented Dec 20, 2024

Can you try Svelte 5.15.0 in your project if it fixes the issue? I've sent a change to add the worker condition, so it should work better now. If it doesn't cause other build tooling regressions that requires a revert there, I think it would be the best fix given the case here.

@GoodLucky777
Copy link
Author

Can you try Svelte 5.15.0 in your project if it fixes the issue? I've sent a change to add the worker condition, so it should work better now. If it doesn't cause other build tooling regressions that requires a revert there, I think it would be the best fix given the case here.

It seems the build error is fixed in Svelte 5.15.0.

@bluwy
Copy link
Member

bluwy commented Dec 25, 2024

I'll close this for now as fixed then. Thanks for testing!

@bluwy bluwy closed this as completed Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants