-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
needs triageIssue needs to be triagedIssue needs to be triaged
Description
Astro Info
Astro: 5.16.3
@astrojs/cloudflare: 12.6.3
Node: v22.x
Package Manager: pnpm 10.11.0
Describe the Bug
When building an Astro project with the Cloudflare adapter in hybrid mode, the generated dist/_worker.js/index.js contains import paths that reference files in dist/_worker.js/_astro/, but the actual files are generated in dist/_astro/.
Example of the incorrect import in dist/_worker.js/index.js:
import { renderers } from './_astro/[email protected]';Actual file location:
dist/_astro/[email protected]
Expected file location (per the import):
dist/_worker.js/_astro/[email protected]
This causes deployment to Cloudflare Pages to fail with module resolution errors.
Steps to Reproduce
- Create a new Astro project with hybrid output mode
- Add @astrojs/cloudflare adapter with config:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';
export default defineConfig({
output: 'hybrid',
adapter: cloudflare({
platformProxy: { enabled: true },
routes: { strategy: 'auto' }
})
});- Run
pnpm build - Observe that
dist/_worker.js/index.jsimports from./_astro/path - Observe that actual files are in
dist/_astro/notdist/_worker.js/_astro/ - Deploy with
wrangler pages deploy distfails with:Could not resolve "./_astro/_@astrojs-ssr-adapter..."
Expected Behavior
Either:
- The import paths in
dist/_worker.js/index.jsshould reference../_astro/(going up one level), OR - The SSR adapter files should be copied/generated into
dist/_worker.js/_astro/
Current Workaround
We use a post-build script that copies files:
// fix-worker-imports.mjs
import { cpSync, existsSync } from 'fs';
import { join } from 'path';
const distDir = './dist';
const astroDir = join(distDir, '_astro');
const workerAstroDir = join(distDir, '_worker.js', '_astro');
if (existsSync(astroDir)) {
cpSync(astroDir, workerAstroDir, { recursive: true });
console.log('Copied _astro to _worker.js/_astro');
}Then in package.json:
"build": "astro build && node fix-worker-imports.mjs"Environment
- OS: macOS
- Node: v22.x
- pnpm: 10.11.0
- Deployment: Cloudflare Pages
Additional Context
This bug was also reported in #13163 but was closed as needs-repro. This issue provides a clear reproduction and workaround. This is a critical bug that prevents deployment to Cloudflare Pages without workarounds.
Metadata
Metadata
Assignees
Labels
needs triageIssue needs to be triagedIssue needs to be triaged