Error: A node.js API is used
Answered
Boby posted this in #help-forum
BobyOP
I am using the
I am on:
when I comment out this code, it will work fine.
I also tried downgrading the packge to 14.2.3 but I was getting another error that
dotenv
module and I am getting this error, PFA.I am on:
"next": "^15.0.1",
when I comment out this code, it will work fine.
import { drizzle } from "drizzle-orm/neon-http";
import { neon } from "@neondatabase/serverless";
import * as schema from "./schema"
import { config } from "dotenv";
config({ path: ".env.local" }); // or .env.local
const sql = neon(process.env.DATABASE_URL!);
export const db = drizzle(sql,{schema});
I also tried downgrading the packge to 14.2.3 but I was getting another error that
crytpo module can't be bundled
something related to dotenv
module.Answered by joulev
Well I don’t know what your past projects looked like. Have you tried my suggestion of simply removing dotenv because it’s doing something nextjs already does for you?
21 Replies
can you share the filename?
does it work if you remove dotenv? you don't need dotenv in nextjs and most likely it's trying to read the .env file which is not allowed in the edge runtime
BobyOP
sorry, but what do you mean by sharing the filename?
like.. what's the name of the file you executing
BobyOP
I am just trying to run my application, that above code comes from the
drizzle.config.ts
@B33fb0n3
can you share your
package.json
?drizzle.config.ts should only export drizzle configurations for the drizzle CLI. You need to import neon and declare the db object in a different file
drizzle.config.ts is for drizzle-kit the CLI, not drizzle-orm (yes they are separate, different things and if you don’t need the CLI you don’t need drizzle.config.ts)
An example drizzle.config.ts is this (taken from their documentation):
import { defineConfig } from "drizzle-kit";
export default defineConfig({
dialect: "postgresql",
schema: "./src/schema.ts",
out: "./drizzle",
});
import { defineConfig } from "drizzle-kit";
export default defineConfig({
dialect: "postgresql",
schema: "./src/schema.ts",
out: "./drizzle",
});
BobyOP
I am sorry, it's
db/index.ts
, I do have a drizzle.config.ts
setup correctly in my project, I am able to perform database related tasks as well in my projectIn db/index.ts, don’t use dotenv.
BobyOP
So I can directly do it without using .env module, with
.env.local
Nextjs automatically loads environment variables to you, and as I said, dotenv reads files which is not allowed in the edge runtime.
Don’t use dotenv there.
Don’t use dotenv there.
BobyOP
but I have used dotenv in past for one of my another next.js project it was working fine.
I was on version 14
I was on version 14
Well I don’t know what your past projects looked like. Have you tried my suggestion of simply removing dotenv because it’s doing something nextjs already does for you?
Answer
BobyOP
Okay, I will try doing it and I will get back to you
Thanks for your time and help
BobyOP
thanks @joulev it's working now,
I have removed this lines of code
I have removed this lines of code
import { config } from "dotenv";
config({ path: ".env.local" }); // or .env.local
and it's working fine
thanks @B33fb0n3 it's working now