Prisma Client v6.7.0 issue

Hi guys, I was setting up a Nodejs server using typescript. To query my postgresql database I'm using Prisma ORM, I setted up it following the documentation for relational databases step by step but when I stat Nodejs server it returns this error:
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
at new PrismaClient (C:\Users\marco\Desktop\byte_heaven_test\server\node_modules\.prisma\client\default.js:43:11)
at Object.<anonymous> (C:\Users\marco\Desktop\byte_heaven_test\server\src\server.ts:14:30)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Module._compile (C:\Users\marco\Desktop\byte_heaven_test\server\node_modules\source-map-support\source-map-support.js:568:25)
at Module.m._compile (C:\Users\marco\AppData\Local\Temp\ts-node-dev-hook-960092578704798.js:69:33)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at require.extensions..jsx.require.extensions..js (C:\Users\marco\AppData\Local\Temp\ts-node-dev-hook-960092578704798.js:114:20)
at require.extensions.<computed> (C:\Users\marco\AppData\Local\Temp\ts-node-dev-hook-960092578704798.js:71:20)
at Object.nodeDevHook [as .ts] (C:\Users\marco\Desktop\byte_heaven_test\server\node_modules\ts-node-dev\lib\hook.js:63:13)
at Module.load (node:internal/modules/cjs/loader:1208:32)
[ERROR] 17:36:42 Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
at new PrismaClient (C:\Users\marco\Desktop\byte_heaven_test\server\node_modules\.prisma\client\default.js:43:11)
at Object.<anonymous> (C:\Users\marco\Desktop\byte_heaven_test\server\src\server.ts:14:30)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Module._compile (C:\Users\marco\Desktop\byte_heaven_test\server\node_modules\source-map-support\source-map-support.js:568:25)
at Module.m._compile (C:\Users\marco\AppData\Local\Temp\ts-node-dev-hook-960092578704798.js:69:33)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at require.extensions..jsx.require.extensions..js (C:\Users\marco\AppData\Local\Temp\ts-node-dev-hook-960092578704798.js:114:20)
at require.extensions.<computed> (C:\Users\marco\AppData\Local\Temp\ts-node-dev-hook-960092578704798.js:71:20)
at Object.nodeDevHook [as .ts] (C:\Users\marco\Desktop\byte_heaven_test\server\node_modules\ts-node-dev\lib\hook.js:63:13)
at Module.load (node:internal/modules/cjs/loader:1208:32)
[ERROR] 17:36:42 Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
I don't know why the server returns this error beacuse I have already configured Prisma and Prisma client and also I have already run the command
npx prisma generate
npx prisma generate
. I have attached my
schema.prisma
schema.prisma
file and
package.json
package.json
.
8 Replies
Prisma AI Help
Prisma AI Help4mo ago
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the #ask-ai channel awaits if you're curious!
jonfanz
jonfanz4mo ago
I’m unable to open your schema on mobile, but are you using a custom output path? If so, you should import from that and not from @prisma/client
ahduaehfkda
ahduaehfkdaOP4mo ago
Thanks for your reply but the output path is the same written by Prisma Client and is the same written on the documentation.
No description
jonfanz
jonfanz4mo ago
Yes, I meant in your code, not in the Schema. You most likely have this line somewhere:
import { PrismaClient } from '@prisma/client'
import { PrismaClient } from '@prisma/client'
ahduaehfkda
ahduaehfkdaOP4mo ago
// utils/prismaClient.ts
import { PrismaClient } from '@prisma/client' // Prisma Client IMPORT

const globalForPrisma = globalThis as unknown as { prisma: PrismaClient }

export const prisma = globalForPrisma.prisma || new PrismaClient()

if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
// utils/prismaClient.ts
import { PrismaClient } from '@prisma/client' // Prisma Client IMPORT

const globalForPrisma = globalThis as unknown as { prisma: PrismaClient }

export const prisma = globalForPrisma.prisma || new PrismaClient()

if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
// src/server.ts
import express, { Application } from "express";
import { appRouter } from "./router";
import { createContext } from "./trpc";
import { prisma } from "./utils/prismaClient";
import * as trpcExpress from "@trpc/server/adapters/express";
import cors from "cors";

const app: Application = express();
const port = 8080;

app.use(cors());
app.use(express.json());

app.get("/test", (req: any, res: any) => {
async function main() {
const users = await prisma.users.findAll();
console.log(users);
}

main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})

});

app.use(
"/api/trpc",
trpcExpress.createExpressMiddleware({
router: appRouter,
createContext,
}),
);

app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
// src/server.ts
import express, { Application } from "express";
import { appRouter } from "./router";
import { createContext } from "./trpc";
import { prisma } from "./utils/prismaClient";
import * as trpcExpress from "@trpc/server/adapters/express";
import cors from "cors";

const app: Application = express();
const port = 8080;

app.use(cors());
app.use(express.json());

app.get("/test", (req: any, res: any) => {
async function main() {
const users = await prisma.users.findAll();
console.log(users);
}

main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})

});

app.use(
"/api/trpc",
trpcExpress.createExpressMiddleware({
router: appRouter,
createContext,
}),
);

app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
I have created this simple server, but when I run it it still returns the same error.
jonfanz
jonfanz4mo ago
Yup, change the first line of utils/prismaClient.ts. it should have the relative path to your generated client, NOT @prisma/client.
ahduaehfkda
ahduaehfkdaOP4mo ago
Thaks bro for helping me, now it works and sorry for my oversight on utils/prismaClient.ts.
jonfanz
jonfanz4mo ago
No problem! Going to mark this as resolved

Did you find this page helpful?