Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit c22bb21

Browse files
fix(cloudflare): using solid with client directive breaks build (#212)
Co-authored-by: Emanuele Stoppa <602478+ematipico@users.noreply.github.com>
1 parent 317bd95 commit c22bb21

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

.changeset/itchy-ears-jam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/cloudflare': patch
3+
---
4+
5+
fixes an issue where projects using `@astrojs/solid-js` were unusable, due to wrong vite config

packages/cloudflare/src/index.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,6 @@ export default function createIntegration(args?: Options): AstroIntegration {
152152
find: 'react-dom/server',
153153
replacement: 'react-dom/server.browser',
154154
},
155-
{
156-
find: 'solid-js/web',
157-
replacement: 'solid-js/web/dist/server',
158-
},
159-
{
160-
find: 'solid-js',
161-
replacement: 'solid-js/dist/server',
162-
},
163155
];
164156

165157
if (Array.isArray(vite.resolve.alias)) {
@@ -170,6 +162,11 @@ export default function createIntegration(args?: Options): AstroIntegration {
170162
}
171163
}
172164

165+
vite.resolve.conditions ||= [];
166+
// We need those conditions, previous these conditions where applied at the esbuild step which we removed
167+
// https://github.com/withastro/astro/pull/7092
168+
vite.resolve.conditions.push('workerd', 'worker');
169+
173170
vite.ssr ||= {};
174171
vite.ssr.target = 'webworker';
175172
vite.ssr.noExternal = true;
@@ -202,6 +199,17 @@ export default function createIntegration(args?: Options): AstroIntegration {
202199
...vite.define,
203200
};
204201
}
202+
// we thought that vite config inside `if (target === 'server')` would not apply for client
203+
// but it seems like the same `vite` reference is used for both
204+
// so we need to reset the previous conflicting setting
205+
// in the future we should look into a more robust solution
206+
if (target === 'client') {
207+
vite.resolve ||= {};
208+
vite.resolve.conditions ||= [];
209+
vite.resolve.conditions = vite.resolve.conditions.filter(
210+
(c) => c !== 'workerd' && c !== 'worker'
211+
);
212+
}
205213
},
206214
'astro:build:done': async ({ pages, routes, dir, logger }) => {
207215
const PLATFORM_FILES = ['_headers', '_redirects', '_routes.json'];

0 commit comments

Comments
 (0)