-
Notifications
You must be signed in to change notification settings - Fork 5
Description
First off THANK YOU to everyone who made this happen! I love apostrophe CMS and astro and to have them together is a dream come true for me. Now that I got my fan boy out of the way, onto the issue I ran into. I am trying to deploy the frontend part of my site to cloudflare pages and have run into an issue. I read in the docs here that seems to strongly suggest that this should be possible. Please let me know if I am mistaken though.
The short version is that it seems this extension is using the node API node:http which is not yet supported in cloudflare as documented here at the time I tried this. (hopefully that changes soon!) I also found that this extension uses the node API node:assert but that is supported by cloudflare so we are good there.
It builds fine in cloudflare pages, but as soon as I try to view the page in a browser I get this error in the cloudflare pages dashboard:
{
"wallTime": 1,
"cpuTime": 0,
"truncated": false,
"executionModel": "stateless",
"outcome": "exception",
"scriptVersion": {
"id": "4d18c4c0-3b45-48fa-96c0-efe062ac56a9"
},
"scriptName": "pages-worker--5975519-production",
"diagnosticsChannelEvents": [],
"exceptions": [
{
"name": "Error",
"message": "No such module \"node:http\".\n imported from \"chunks/aposResponse_Dff82EGN.mjs\"",
"timestamp": 1745367621909
}
],
"logs": [
{
"message": [
"00:20:21 [ERROR] Error: No such module \"node:http\".\n imported from \"chunks/aposResponse_Dff82EGN.mjs\""
],
"level": "error",
"timestamp": 1745367621909
}
],
// ... and so on...
}To Reproduce
Step by step instructions to reproduce the behavior:
I created a repo similar to the Apollo example repo with the project split into folders of, backend with apostrpheCMS, and frontend with astro. Everything working great locally.
I then went through the node compatibility notes found in both astro's docs and cloudflare's. Below are some snippets from my project:
wrangler.json Added the required compatibility props in wrangler:
{
"name": "apos-frontend",
"compatibility_flags": ["nodejs_compat"],
"compatibility_date": "2025-04-22",
"pages_build_output_dir": "./dist",
"kv_namespaces": [
{
"binding": "SESSION",
"id": "...."
}
]
}astro.config.mjs page attention, mostly, to the vite.ssr.external value:
import { defineConfig } from 'astro/config'
import tailwindcss from '@tailwindcss/vite'
import cloudflare from '@astrojs/cloudflare'
import apostrophe from '@apostrophecms/apostrophe-astro'
import { loadEnv } from 'vite'
const env = loadEnv('', process.cwd(), 'APOS')
// https://astro.build/config
export default defineConfig({
output: 'server',
adapter: cloudflare({
imageService: 'passthrough',
platformProxy: {
enabled: true,
configPath: 'wrangler.json'
}
}),
integrations: [
apostrophe({
aposHost: 'http://localhost:3000',
widgetsMapping: './src/widgets',
templatesMapping: './src/templates',
includeResponseHeaders: [
'content-security-policy',
'strict-transport-security',
'x-frame-options',
'referrer-policy',
'cache-control'
],
excludeRequestHeaders: [
// For hosting on multiple servers, block the host header
'host'
]
})
],
vite: {
plugins: [tailwindcss()],
ssr: {
// Do not externalize the @apostrophecms/apostrophe-astro plugin, we need
// to be able to use virtual: URLs there
noExternal: ['@apostrophecms/apostrophe-astro'],
external: ['node:assert', 'node:http'] // <------- astro says we also need to add the specific node APIs here for them to be added to the final build in cloudflare.
},
define: {
'process.env.APOS_EXTERNAL_FRONT_KEY': JSON.stringify(env.APOS_EXTERNAL_FRONT_KEY),
'process.env.APOS_HOST': JSON.stringify(env.APOS_HOST)
}
}
})Expected behavior
I expected this to run and render in the cloudflare pages environment based on it being mentioned in the documentation as a place the astro frontend could be deployed to.
Describe the bug
It seems this extension is requiring a node API node:http that is not yet supported on the cloudflare pages platform.
Details
Version of Node.js:
PLEASE NOTE: Only stable LTS versions (10.x and 12.x) are fully supported but we will do our best with newer versions.
22.11.0
Server Operating System:
The server (which might be your dev laptop) on which Apostrophe is running. Linux? MacOS X? Windows? Is Docker involved?
Frontend: Cloudflare Pages
Backend: ApostropheCMS is running on linux with Docker using Coolify to manage it. (but that part is not the problem here)
Additional context:
Add any other context about the problem here. If the problem is specific to a browser, OS or mobile device, specify which.
I made sure to set the "build configuration" settings in cloudflare as follows:
build command: npm run build
build output directory: /dist
root directory path: /frontend
Tried it on Firefox and Chrome, but the above error message came from the cloudflare log stream. https://developers.cloudflare.com/pages/functions/debugging-and-logging/#view-logs-in-the-cloudflare-dashboard.
Let me know if there are any questions! Sorry if I missed anything. Thank you so much!