I am trying to integrate Drizzle into Nuxt 3.
In /server/db/index.ts I have the following
import { sql } from '@vercel/postgres';
import { drizzle } from 'drizzle-orm/vercel-postgres';
import dotenv from 'dotenv';
import * as schema from './schema';
import path from 'path'
dotenv.config({ path: '../../.env' });
export const db = drizzle(sql, { schema });
When I try to import db
into my component I get the following error
500
process.cwd is not a function
at Object.configDotenv (http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/dotenv.js?v=c9c673b9:267:47)
at Object.config (http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/dotenv.js?v=c9c673b9:314:29)
at http://localhost:3000/_nuxt/server/db/index.ts?t=1720792472809:5:8
It was a silly mistake on my part. I was trying to import db
into my component, but I should instead of imported it into an API method and used useFetch
to fetch data from the API into the component.
Once I did that everything works, along with the all the types from my database being available in my component.