-
-
Notifications
You must be signed in to change notification settings - Fork 621
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
[BUG][Postgres][Next 13][API Route][Edge runtime] Can't resolve 'net' #753
Comments
Tried swapping the error@lf/web:dev: - wait compiling /api/contact/route (client and server)...
@lf/web:dev: - error ../../node_modules/pg-connection-string/index.js:72:69
@lf/web:dev: Module not found: Can't resolve 'fs'
@lf/web:dev:
@lf/web:dev: https://nextjs.org/docs/messages/module-not-found
@lf/web:dev:
@lf/web:dev: Import trace for requested module:
@lf/web:dev: ../../node_modules/pg/lib/connection-parameters.js
@lf/web:dev: ../../node_modules/pg/lib/client.js
@lf/web:dev: ../../node_modules/pg/lib/index.js
@lf/web:dev: ../../packages/services/drizzle-orm-client/lib/client.ts
@lf/web:dev: ../../packages/services/drizzle-orm-client/lib/index.ts
@lf/web:dev: ./src/app/api/contact/route.ts
@lf/web:dev: ../../node_modules/next/dist/build/webpack/loaders/next-edge-app-route-loader/index.js?absolutePagePath=%2FUsers%2Fatanas%2FDocuments%2FGitHub%2Flandlord-fusion-t3%2Fapps%2Fweb%2Fsrc%2Fapp%2Fapi%2Fcontact%2Froute.ts&page=%2Fapi%2Fcontact%2Froute&appDirLoader=bmV4dC1hcHAtbG9hZGVyP25hbWU9YXBwJTJGYXBpJTJGY29udGFjdCUyRnJvdXRlJnBhZ2U9JTJGYXBpJTJGY29udGFjdCUyRnJvdXRlJmFwcFBhdGhzPSZwYWdlUGF0aD1wcml2YXRlLW5leHQtYXBwLWRpciUyRmFwaSUyRmNvbnRhY3QlMkZyb3V0ZS50cyZhcHBEaXI9JTJGVXNlcnMlMkZhdGFuYXMlMkZEb2N1bWVudHMlMkZHaXRIdWIlMkZsYW5kbG9yZC1mdXNpb24tdDMlMkZhcHBzJTJGd2ViJTJGc3JjJTJGYXBwJnBhZ2VFeHRlbnNpb25zPXRzeCZwYWdlRXh0ZW5zaW9ucz10cyZwYWdlRXh0ZW5zaW9ucz1qc3gmcGFnZUV4dGVuc2lvbnM9anMmcm9vdERpcj0lMkZVc2VycyUyRmF0YW5hcyUyRkRvY3VtZW50cyUyRkdpdEh1YiUyRmxhbmRsb3JkLWZ1c2lvbi10MyUyRmFwcHMlMkZ3ZWImaXNEZXY9dHJ1ZSZ0c2NvbmZpZ1BhdGg9dHNjb25maWcuanNvbiZiYXNlUGF0aD0mYXNzZXRQcmVmaXg9Jm5leHRDb25maWdPdXRwdXQ9 clientimport { schema } from '@lf/services-drizzle-orm-schema'
import { drizzle } from 'drizzle-orm/node-postgres'
import { Client } from 'pg'
import postgres from 'postgres'
const client = new Client({
connectionString: 'postgresql://postgres:postgres@localhost:54322/postgres'
})
const queryClient = postgres('postgresql://postgres:postgres@localhost:54322/postgres')
client.connect()
// export const db: PostgresJsDatabase<Schema> = drizzle(queryClient, { schema, logger: true })
export const db = drizzle(client, { schema, logger: true }) |
Weird, seem you run it on the client side ... /api/contact/route (client and server) . I am not an expert of Nextjs, but routes are in pages no ? like pages/api |
The Next 13 API routes run on the server. Please note that the same endpoint works OK with I've expected it work out of the box, but it might be the case only for some specific mysql clients
|
The Edge Runtime, which is used by Next.js Middleware, does not support Node.js native APIs. From the Edge Runtime documentation: The Edge Runtime has some restrictions including: Native Node.js APIs are not supported. For example, you can't read or write to the filesystem If you use Vercel : https://vercel.com/templates/next.js/postgres-drizzle |
BTW you are on edge, so you should use serverless runtimes : @neondatabase/serverless, @vercel/postgres, @planetscale/database or D1 by cloudflare |
Thanks for he hints @clifinger! I am using Supabase Postgres, not sure if I can use it with Drizzle on the edge... I've tried adapting the @vercel/postgress client, but it won't connect |
Hello, no you can't as they don't have serverless edge driver in Supabase. For your own logic you can use Edge from supabase ... If it's just to try Drizzle with supabase, you can install NestJS and follow my documentation : https://github.com/canduma/nest-drizzle |
Drizzle is edge ready. You should select a driver that's also edge ready. |
What version of
drizzle-orm
are you using?0.26.5
What version of
drizzle-kit
are you using?0.18.1
Describe the Bug
Next 13 api route handler with
edge
runtime throwsModule not found: Can't resolve 'net'
client
api route
error
Expected behavior
Should be able to use Drizzle Postgres client in a Next 13 edge api route
Environment & setup
No response
The text was updated successfully, but these errors were encountered: