-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
📚 Subject area/topic
Content Collection configuration
📋 Page(s) affected (or suggested, for new content)
https://docs.astro.build/en/guides/content-collections/#defining-collections
📋 Description of content that is out-of-date or incorrect
Recently, I faced an issue related to adding cloudflare adapter for SSR, which I think I narrowed down to exporting something other than the content collection from src/content.config.ts.
I use the astro-paper theme for a site. That theme's content collection config file exports a string const in addition to the actual collections.
export const BLOG_PATH = "src/data/blog";
This const is then imported in another utility file called getPath.ts.
When I added cloudflare adapter to my project, pnpm build started giving an error related to getPath:
14:16:02 [build] Rearranging server assets...
14:16:02 [ERROR] [@astrojs/cloudflare] An unhandled error occurred while running the "astro:build:done" hook
ENOENT: no such file or directory, open 'D:\astro-paper-cloudflare\dist\_worker.js\chunks\getPath_BImV0riY.mjs'
Stack trace:
at async open (node:internal/fs/promises:641:25)
at async Object.afterBuildCompleted (file:///D:/astro-paper-cloudflare/node_modules/.pnpm/@[email protected]_80423d8ba74735b2c16b97c9f0caed57/node_modules/@astrojs/cloudflare/dist/utils/cloudflare-module-loader.js:128:26)
at async withTakingALongTimeMsg (file:///D:/astro-paper-cloudflare/node_modules/.pnpm/[email protected][email protected]_lig_6af3358a8afa341e0e945f6f2fdd3368/node_modules/astro/dist/integrations/hooks.js:32:12)
at async runHookBuildDone (file:///D:/astro-paper-cloudflare/node_modules/.pnpm/[email protected][email protected]_lig_6af3358a8afa341e0e945f6f2fdd3368/node_modules/astro/dist/integrations/hooks.js:456:5)
at async AstroBuilder.run (file:///D:/astro-paper-cloudflare/node_modules/.pnpm/[email protected][email protected]_lig_6af3358a8afa341e0e945f6f2fdd3368/node_modules/astro/dist/core/build/index.js:185:7)
ELIFECYCLE Command failed with exit code 1.
After a day of trying other things, I ultimately figured out that BLOG_PATH variable that was imported from content.config.ts was the culprit. It got fixed when I moved that export to another file.
Now, I'm not fully certain why Astro doesn't like content.config.ts having that export. According to Claude, the issue might be:
When you were importing `BLOG_PATH` from `content.config.ts`, you created a dependency chain that the Cloudflare adapter couldn't handle properly:getPath.ts → imports → content.config.ts content.config.ts → uses astro:content (special Astro module)The problem is:
content.config.tsis a special file - It's processed by Astro's content layer system and usesastro:contentwhich has special build-time behavior- The Cloudflare adapter bundles differently - It needs to create a Worker bundle that runs in Cloudflare's environment
- Circular/complex dependencies with content config - When
getPath.tsimports fromcontent.config.ts, and that config file is used during content collection processing, it can create a bundling issue where the module graph gets confused
Provided that it's true that you shouldn't export other things from that file, I asked on Discord whether this is potentially something that should be in the docs. I was suggested to create an issue here so it can be clarified.
🖥️ Reproduction
Here is a commit that fixes this issue in a fork of the astro-paper repo.