diff --git a/.changeset/gorgeous-grapes-occur.md b/.changeset/gorgeous-grapes-occur.md new file mode 100644 index 000000000..b7bdb396a --- /dev/null +++ b/.changeset/gorgeous-grapes-occur.md @@ -0,0 +1,5 @@ +--- +'@astrojs/cloudflare': patch +--- + +Fixes a bug where Svelte was not working properly when using the Cloudflare adapter diff --git a/packages/cloudflare/src/index.ts b/packages/cloudflare/src/index.ts index 3193683c2..cde231deb 100644 --- a/packages/cloudflare/src/index.ts +++ b/packages/cloudflare/src/index.ts @@ -12,7 +12,7 @@ import { import { createRedirectsFromAstroRoutes } from '@astrojs/underscore-redirects'; import astroWhen from '@inox-tools/astro-when'; import { AstroError } from 'astro/errors'; -import { defaultClientConditions } from 'vite'; +import { defaultServerConditions } from 'vite'; import { type GetPlatformProxyOptions, getPlatformProxy } from 'wrangler'; import { type CloudflareModulePluginExtra, @@ -219,11 +219,15 @@ export default function createIntegration(args?: Options): AstroIntegration { } } - // Support `workerd` and `worker` conditions for the ssr environment + // Support `workerd` and `worker` conditions for the ssr environment + // while also removing the `node` condition to prevent node specific imports // (previously supported in esbuild instead: https://github.com/withastro/astro/pull/7092) vite.ssr ||= {}; vite.ssr.resolve ||= {}; - vite.ssr.resolve.conditions ||= [...defaultClientConditions]; + vite.ssr.resolve.conditions ||= [...defaultServerConditions]; + vite.ssr.resolve.conditions = vite.ssr.resolve.conditions.filter( + (condition) => condition !== 'node' + ); vite.ssr.resolve.conditions.push('workerd', 'worker'); vite.ssr.target = 'webworker'; diff --git a/packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte b/packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte index a8a85aeb4..c061eba61 100644 --- a/packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte +++ b/packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte @@ -1 +1,9 @@ +