H
Hono7mo ago
Arjun

Module not found: Can't resolve 'path' with Hono Drizzle

The Error
./node_modules/dotenv/lib/main.js:2:1
Module not found: Can't resolve 'path'
./node_modules/dotenv/lib/main.js:2:1
Module not found: Can't resolve 'path'
The issue is somewhere either in this file
import { Hono } from "hono";

import { db } from "@/db/drizzle";
import { accounts } from "@/db/schema";

const app = new Hono().get("/", async (c) => {
console.log("running accounts query");


const data = async () => {
try {
const dbFetch = await db
.select({
id: accounts.id,
name: accounts.name,
})
.from(accounts);
return dbFetch;
} catch (error) {
console.log("Error fetching data from DB", error);
}
// when I comment out the data function and replace what's being passed to c.json() with something fixed then there is no issue but when I just try to run this function even when its not being passed to c.json() then it throws the same error

};

return c.json({ data });
});

export default app;
import { Hono } from "hono";

import { db } from "@/db/drizzle";
import { accounts } from "@/db/schema";

const app = new Hono().get("/", async (c) => {
console.log("running accounts query");


const data = async () => {
try {
const dbFetch = await db
.select({
id: accounts.id,
name: accounts.name,
})
.from(accounts);
return dbFetch;
} catch (error) {
console.log("Error fetching data from DB", error);
}
// when I comment out the data function and replace what's being passed to c.json() with something fixed then there is no issue but when I just try to run this function even when its not being passed to c.json() then it throws the same error

};

return c.json({ data });
});

export default app;
This file may help @/db/drizzle.ts
import "dotenv/config";

import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";

const connectionString = process.env.DATABASE_URL!;

// Disable prefetch as it is not supported for "Transaction" pool mode
export const client = postgres(connectionString, { prepare: false });
export const db = drizzle(client);
import "dotenv/config";

import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";

const connectionString = process.env.DATABASE_URL!;

// Disable prefetch as it is not supported for "Transaction" pool mode
export const client = postgres(connectionString, { prepare: false });
export const db = drizzle(client);
21 Replies
Nico
Nico7mo ago
What run-time are you using? Do you have dotenv installed properly?
Arjun
ArjunOP7mo ago
I'm using bun and yes I have dotenv installed
Nico
Nico7mo ago
For bun you don’t need dotenv and you use process.env or Bun.env directly I’m not sure if that will fix the issue
Arjun
ArjunOP7mo ago
nope
Nico
Nico7mo ago
To confirm you removed that import and dotenv package and it did not fix it?
Arjun
ArjunOP7mo ago
Yes I did that. But I ran into this
No description
Nico
Nico7mo ago
What is this running on?
Arjun
ArjunOP7mo ago
next js, ms edge, arch linux
Aditya Mathur
Aditya Mathur7mo ago
Wait so are you using Cloudflare libs in nextjs?
Arjun
ArjunOP7mo ago
I wasn't intending to I just did a basic installation
Aditya Mathur
Aditya Mathur7mo ago
Cloudflare libs will only work in cloudflare runtimes like cloudflare pages and workers. Which docs did you follow? Can you point me to them so that I can cross check if this is the issue I would suggest you to follow the vercel and nextjs docs for setting things up
Arjun
ArjunOP7mo ago
I did that and that runs into this issue now
Arjun
ArjunOP7mo ago
No description
Arjun
ArjunOP7mo ago
I followed the official supabase and drizzle docs
Aditya Mathur
Aditya Mathur7mo ago
Just install the crypto package that should resolve this Can you share the link?
Arjun
ArjunOP7mo ago
Man I'm honestly tired of all this. So sick of grinding and not getting a job and facing rejections daily. I don't even see the point in building this project cuz I know I still won't get hired Wait
Arjun
ArjunOP7mo ago
Drizzle ORM - Drizzle with Supabase Database
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Aditya Mathur
Aditya Mathur7mo ago
This is something outside my scope of work, but just relax and take a break. Everyone is low at some point, I am too on a daily basis (biggest con of being a programmer). Just try to remember what all have you accomplished and start with a fresh mind. Relax everything will turn out good in the end. I will go through these and check why these issues might have been occurring.
Arjun
ArjunOP6mo ago
Found the fix I was running it on edge which Supabase doesn't support. I changed it to nodejs and it worked
Aditya Mathur
Aditya Mathur6mo ago
Please mark this as solved, thank you
Want results from more Discord servers?
Add your server