Astro Info
Astro v6.1.1
Vite v7.3.1
Node v22.18.0
System Windows (x64)
Package Manager npm
Output static
Adapter @astrojs/cloudflare (v13.1.4)
Integrations astro:db
@astrojs/db/file-url
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I had an Astro site with AstroDB working fine in dev but could not get it to deploy to Cloudflare pages using a remote db hosted by Turso. No matter what I tried, the build always failed with:
Invalid URL string.
Location:
..../node_modules/.vite/deps_ssr/chunk-4647JXVN.js?v=6cff316a:63:14
at Object.runInlinedModule (workers/runner-worker/index.js:218:4)
at CustomModuleRunner.cachedRequest (workers/runner-worker/vite/module-runner:1111:73)
at Object.runInlinedModule (workers/runner-worker/index.js:218:4)
at CustomModuleRunner.cachedRequest (workers/runner-worker/vite/module-runner:1111:73)
All the usual suspects of mis-specified environment variables, bad url or access tokens did nothing to solve the problem. npx astro db push works so the ASTRO_DB_REMOTE_URL and ASTRO_DB_APP_TOKEN .env parameters appear to be correct. After hours of troubleshooting and countless permutations, compatibility flags, wrangler.toml tweaks, etc. I could never get past this. So I started on a fresh Windows machine, built a minimal example, and I'm running into the exact same issue when building locally. I think there's something deeper going on specifically with the interaction between Astrodb and the Cloudflare adapter.
Since StackBlitz does not support @astrojs/cloudflare here's a summary of the minimal steps.
On Windows, an otherwise minimal Astro v6 project using @astrojs/db (remote/libSQL) and the Cloudflare adapter fails during astro build --remote with Invalid URL string.. This appears to be a Windows path vs file:// URL serialization bug: during SSR/module-runner setup the manifest is deserialized and code attempts new URL(serializedManifest.rootDir) (and similar), but at least one of those fields is not a valid URL.
Environment
- OS: Windows 10 (10.0.19045)
- Shell: PowerShell
- Node:
v22.18.0
- npm:
11.5.2
- astro:
6.1.1
- @astrojs/db:
0.20.1
- @astrojs/cloudflare:
13.1.4
- wrangler:
4.77.0
Minimal repro steps
- Create a new project:
npm create astro@latest . -- --template basics --install --git false
Add Astro DB and define a single table:
npx astro@latest add db --yes
db/config.ts:
import { defineDb, defineTable, column } from 'astro:db';
export default defineDb({
tables: {
Items: defineTable({
columns: {
id: column.number({ primaryKey: true }),
name: column.text(),
},
}),
},
});
Add Cloudflare adapter:
npx astro@latest add cloudflare --yes
astro.config.mjs:
import { defineConfig } from 'astro/config';
import db from '@astrojs/db';
import cloudflare from '@astrojs/cloudflare';
export default defineConfig({
integrations: [db()],
adapter: cloudflare(),
});
Configure DB remote env vars (example; token redacted):
.env:
ASTRO_DB_REMOTE_URL=libsql://<your-db>.turso.io
ASTRO_DB_APP_TOKEN=<redacted>
Build with remote mode:
npm run build --remote
Build fails:
[ERROR] [astro:db] An unhandled error occurred while running the "astro:build:setup" hook
Invalid URL string.
Location:
C:/Users/.../node_modules/.vite/deps_ssr/chunk-4647JXVN.js?...:63:14
Stack trace:
at deserializeManifest (...)
at Object.runInlinedModule (workers/runner-worker/index.js:218:4)
Additional details / suspected root cause
The thrown error originates from code equivalent to:
rootDir: new URL(serializedManifest.rootDir),
srcDir: new URL(serializedManifest.srcDir),
publicDir: new URL(serializedManifest.publicDir),
outDir: new URL(serializedManifest.outDir),
cacheDir: new URL(serializedManifest.cacheDir),
If any of these values are plain Windows paths (e.g. C:... or C:/...) rather than valid file:// URLs, new URL(...) will throw Invalid URL string..
This only reproduces once:
Cloudflare adapter is enabled (build mode becomes server), and
Astro DB remote build is enabled (--remote)
This appears to be the exact same problem I was experiencing in Cloudfare deployments. Happy to provide any additional information. This is a show-stopper at the moment!
What's the expected result?
astro build --remote should complete successfully (or fail with a clear DB connection/auth error if credentials are wrong), not with Invalid URL string
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-ak5ik59o?file=astro.config.mjs
Participation
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I had an Astro site with AstroDB working fine in dev but could not get it to deploy to Cloudflare pages using a remote db hosted by Turso. No matter what I tried, the build always failed with:
Invalid URL string.
Location:
All the usual suspects of mis-specified environment variables, bad url or access tokens did nothing to solve the problem.
npx astro db pushworks so the ASTRO_DB_REMOTE_URL and ASTRO_DB_APP_TOKEN .env parameters appear to be correct. After hours of troubleshooting and countless permutations, compatibility flags, wrangler.toml tweaks, etc. I could never get past this. So I started on a fresh Windows machine, built a minimal example, and I'm running into the exact same issue when building locally. I think there's something deeper going on specifically with the interaction between Astrodb and the Cloudflare adapter.Since StackBlitz does not support @astrojs/cloudflare here's a summary of the minimal steps.
On Windows, an otherwise minimal Astro v6 project using
@astrojs/db(remote/libSQL) and the Cloudflare adapter fails duringastro build --remotewithInvalid URL string.. This appears to be a Windows path vsfile://URL serialization bug: during SSR/module-runner setup the manifest is deserialized and code attemptsnew URL(serializedManifest.rootDir)(and similar), but at least one of those fields is not a valid URL.Environment
v22.18.011.5.26.1.10.20.113.1.44.77.0Minimal repro steps
npm create astro@latest . -- --template basics --install --git falseAdd Astro DB and define a single table:
npx astro@latest add db --yesdb/config.ts:
Add Cloudflare adapter:
npx astro@latest add cloudflare --yesastro.config.mjs:
Configure DB remote env vars (example; token redacted):
.env:
Build with remote mode:
npm run build --remoteBuild fails:
Additional details / suspected root cause
The thrown error originates from code equivalent to:
If any of these values are plain Windows paths (e.g. C:... or C:/...) rather than valid file:// URLs, new URL(...) will throw Invalid URL string..
This only reproduces once:
Cloudflare adapter is enabled (build mode becomes server), and
Astro DB remote build is enabled (--remote)
This appears to be the exact same problem I was experiencing in Cloudfare deployments. Happy to provide any additional information. This is a show-stopper at the moment!
What's the expected result?
astro build --remote should complete successfully (or fail with a clear DB connection/auth error if credentials are wrong), not with Invalid URL string
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-ak5ik59o?file=astro.config.mjs
Participation