New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LibsqlError: URL_INVALID when deploying to Render #1121
Comments
Facing the same issue with Cloudflare workers |
Same issue with Cloudflare pages (works well in local)
Using Astro, Drizzle and Turso: // db.ts
import { drizzle } from "drizzle-orm/libsql";
import { createClient } from "@libsql/client/web";
export const client = createClient({
url: import.meta.env.TURSO_URL,
authToken: import.meta.env.TURSO_AUTH_TOKEN,
});
export const db = drizzle(client); Environment variables in Cloudflare:
|
When I use url string directly in the client (instead of using The related issue: withastro/astro#6130 |
It worked for me. import { createClient } from '@libsql/client/web';
const dbClient = () => createClient({
url: import.meta.env.TURSO_URL,
authToken: import.meta.env.TURSO_AUTH_TOKEN,
}); |
Hi @niklauslee the issue here is that the environment vars are not replaced at compile time. They are instead proxied to the request env vars at runtime (in cloudflare env), therefore you need to access the vars after a request has been made to your worker. This means that the suggested change from @RafaelRamosR works when called from inside an api request or inside an astro file, or middleware. |
@RafaelRamosR @AirBorne04 I am getting this error: Error [LibsqlError]: URL_INVALID: The URL is not in a valid format on vercel build failed, local development is working fine but deployment is failing
|
@ArshErgon you need to use a factory function createClient = () => because the env vars can only be read when a request is ongoing not statically. |
Hey @AirBorne04 thanks for the reply but error is still the same
or can this file cause error?
edit: I finally found out what I was doing wrong: |
@ArshErgon yeah ok, good you got it working. That is correct in a standard VITE project you need to prefix the vars. I thought you would also be in the AstroJS / Cloudflare environment (as @niklauslee ) where the case is different. So i think also the initial report is rather related to wrong env reading than turso? @rakis10 ? |
Localy works, but when deploying on Render.
db.js:
"dependencies": {
"@libsql/client": "^0.5.2",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.29.4",
"ejs": "^3.1.9",
"events": "^3.3.0",
"express": "^4.18.2",
"express-session": "^1.17.3",
"fs": "^0.0.1-security",
"nodemon": "^3.0.2",
"passport": "^0.7.0",
"passport-local": "^1.0.0"
},
/opt/render/project/src/node_modules/@libsql/core/lib-cjs/uri.js:12
throw new api_js_1.LibsqlError("The URL is not in a valid format", "URL_INVALID");
^
LibsqlError: URL_INVALID: The URL is not in a valid format
at parseUri (/opt/render/project/src/node_modules/@libsql/core/lib-cjs/uri.js:12:15)
at expandConfig (/opt/render/project/src/node_modules/@libsql/core/lib-cjs/config.js:35:39)
at createClient (/opt/render/project/src/node_modules/@libsql/client/lib-cjs/node.js:28:52)
at Object. (/opt/render/project/src/db.js:4:16)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18) {
code: 'URL_INVALID',
rawCode: undefined,
[cause]: undefined
}
Node.js v20.11.1
The text was updated successfully, but these errors were encountered: