Pixel
Pixel
NNuxt
Created by Pixel on 12/21/2024 in #❓・help
Using Deno Deploy with Drizzle and MySQL2
Hi! I was trying to deploy a nuxt project to deno deploy today. It uses mysql2 and drizzle for the database stuff. However, after deploying it, I got this error:
[nuxt] [request error] [unhandled] [500] [unenv] net.connect is not implemented yet!
[nuxt] [request error] [unhandled] [500] [unenv] net.connect is not implemented yet!
It seems like nuxt uses unenv under-the-hood which tries to polyfill net.connect, but net.connect specifically isn't implemented yet. The issue presumably happens when mysql2 tries to connect to my db, because it uses this package under-the-hood. Do I have it right? And if so, how can I fix it? I tried to set clientNodeCompat to false in the nuxt config without any success. It's a very simple nuxt project. Basically just npx nuxi@latest init with drizzle added to it. I would make the github repo public, but I'm not that confident I haven't leaked some credential somewhere.
// nuxt.config.ts
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: "2024-11-01",
devtools: { enabled: true },
modules: ["@nuxtjs/tailwindcss"],
runtimeConfig: {
dbUrl: process.env.DATABASE_URL,
},
});

// drizzle.config.ts
import "dotenv/config";
import { defineConfig } from "drizzle-kit";

export default defineConfig({
out: "./drizzle",
schema: "./server/db/schema.ts",
dialect: "mysql",
dbCredentials: {
url: process.env.DATABASE_URL!,
},
});

// server/utilts/useDrizzle.ts
import "dotenv/config";
import { drizzle } from "drizzle-orm/mysql2";

import * as schema from "@/server/db/schema";
import * as relations from "@/server/db/relations";

export const tables = schema;

export function useDrizzle() {
const runtimeConfig = useRuntimeConfig();
const db = drizzle(runtimeConfig.dbUrl, {
schema: {
...schema,
...relations,
},
mode: "default",
});
return db;
}
// nuxt.config.ts
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: "2024-11-01",
devtools: { enabled: true },
modules: ["@nuxtjs/tailwindcss"],
runtimeConfig: {
dbUrl: process.env.DATABASE_URL,
},
});

// drizzle.config.ts
import "dotenv/config";
import { defineConfig } from "drizzle-kit";

export default defineConfig({
out: "./drizzle",
schema: "./server/db/schema.ts",
dialect: "mysql",
dbCredentials: {
url: process.env.DATABASE_URL!,
},
});

// server/utilts/useDrizzle.ts
import "dotenv/config";
import { drizzle } from "drizzle-orm/mysql2";

import * as schema from "@/server/db/schema";
import * as relations from "@/server/db/relations";

export const tables = schema;

export function useDrizzle() {
const runtimeConfig = useRuntimeConfig();
const db = drizzle(runtimeConfig.dbUrl, {
schema: {
...schema,
...relations,
},
mode: "default",
});
return db;
}
5 replies