DATABASE_URL Type Error
async handle(c: AppContext) {
// Get validated data
const prisma = getPrisma(c.env.DATABASE_URL);
const data = await prisma.menuItems.findMany();
// Implement your own object list here
return {
success: true,
menu_items: data
};
}
getting error in dburl
Property 'DATABASE_URL' does not exist on type 'Env'.
The error Property 'DATABASE_URL' does not exist on type 'Env' means that TypeScript doesn't know
that DATABASE_URL exists on your Env type (used by Hono or your app's context).
✅ Fix: Add DATABASE_URL to your Env Type Definition
If you're using Hono with typed Env, you need to extend or define your environment types properly.
Here’s how to do it:
Option 1: If you're using your own AppContext type
Update your AppContext or Env definition like this:
ts
type Env = {
Bindings: {
DATABASE_URL: string;
// other env vars if needed
};
};
type AppContext = Context<Env>;
Then in your route handler:
ts
async handle(c: AppContext) {
const prisma = getPrisma(c.env.DATABASE_URL);
const data = await prisma.menuItems.findMany();
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/6
return {
success: true,
menu_items: data
};
}
Option 2: If you're not using custom types (Quick Patch)
Just cast c.env:
ts
const { DATABASE_URL } = c.env as { DATABASE_URL: string };
const prisma = getPrisma(DATABASE_URL);
Bonus: If you're using .env file (local dev)
Make sure to load the env file using dotenv:
ts
import 'dotenv/config';
And access it directly:
ts
const prisma = getPrisma(process.env.DATABASE_URL!);
Let me know if you're using Cloudflare Workers, Node.js, or Bun — as env handling slightly differs per
runtime.
export type AppContext = Context<{ Bindings: Env }>;
see this
Great — thanks for the clarity.
You're using this:
ts
export type AppContext = Context<{ Bindings: Env }>;
That means your Env type needs to include a DATABASE_URL property explicitly. Currently, TypeScript
doesn’t know what's inside Env, so it complains.
✅ Fix: Define Env like this
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 2/6
ts
export type Env = {
DATABASE_URL: string;
// add other bindings if needed
};
So your full context setup should be:
ts
export type Env = {
DATABASE_URL: string;
};
export type AppContext = Context<{ Bindings: Env }>;
🧠 Why this works
With this setup:
c.env is typed as Env
So c.env.DATABASE_URL is recognized and properly typed
TypeScript won't throw Property 'DATABASE_URL' does not exist
Let me know if you're using Hono on Cloudflare Workers or Node.js, because some setups (like CF
Workers) require Bindings to include KV, secrets, or Durable Objects as well.
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it
again.
at new PrismaClient
(file:///C:/Users/Developer/Documents/hono-
server/node_modules/.prisma/client/edge.js:43:11)
at getPrisma (file:///C:/Users/Developer/Documents/hono-
server/prisma/prismaFunction.ts:6:17)
at MenuItemList.handle
(file:///C:/Users/Developer/Documents/hono-server/src/endpoints/menu-items/menu-items-
list.ts:32:24)
at MenuItemList.execute
(file:///C:/Users/Developer/Documents/hono-
server/node_modules/chanfana/dist/index.mjs:656:25)
at Array.<anonymous>
(file:///C:/Users/Developer/Documents/hono-
server/node_modules/chanfana/dist/index.mjs:238:12)
at #dispatch
(file:///C:/Users/Developer/Documents/hono-server/node_modules/hono/dist/hono-
base.js:188:37)
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 3/6
at Hono2.fetch
(file:///C:/Users/Developer/Documents/hono-server/node_modules/hono/dist/hono-
base.js:214:17)
at fetchDispatcher
(file:///C:/Users/Developer/Documents/hono-server/.wrangler/tmp/bundle-
W3qdMh/middleware-loader.entry.ts:54:17)
at __facade_invokeChain__
(file:///C:/Users/Developer/Documents/hono-
server/node_modules/wrangler/templates/middleware/common.ts:53:9)
at Object.next
(file:///C:/Users/Developer/Documents/hono-
server/node_modules/wrangler/templates/middleware/common.ts:50:11
This error:
typescript
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it
again.
means that Prisma client hasn't been generated, or the generated files are out of sync with your
schema.
✅ How to Fix It Step-by-Step
1. Run the following in your project root:
bash
npx prisma generate
This will generate the .prisma/client folder and sync it with your schema.prisma.
2. Check prisma/schema.prisma Exists
Make sure your folder structure looks like this:
bash
/prisma
└── schema.prisma
And your schema.prisma has:
prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["clientExtensions"] // if using edge client
}
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 4/6
generator edge_client {
provider = "prisma-client-js"
output = "./../node_modules/.prisma/client/edge"
}
datasource db {
provider = "postgresql" // or sqlite/mysql/etc.
url = env("DATABASE_URL")
}
3. Install Dependencies
Make sure all necessary Prisma packages are installed:
bash
npm install @prisma/client prisma
If you're using Prisma with Edge Runtime (e.g., Cloudflare Workers), install:
bash
npm install @prisma/client @prisma/client/edge
And your import should be:
ts
import { PrismaClient } from '@prisma/client/edge';
⚠️ You still need to run npx prisma generate even with the edge client.
4. Optional: Clean Cache
If you still face issues:
bash
rm -rf node_modules/.prisma
rm -rf node_modules/@prisma/client
npx prisma generate
✅ Summary Checklist
Step Description
✅ schema.prisma exists
✅ Ran npx prisma generate
✅ Installed @prisma/client
✅ Correct PrismaClient import (edge or standard)
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 5/6
Let me know if you're using Bun, Cloudflare Workers, or Node.js, so I can guide based on your runtime
too.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 6/6