Expose types to the frontend for Next.js
See original GitHub issueBug description
I am playing around with prisma and getting that async_hooks error and its a rather weird thing. Let me explain: If i have this:
import { prisma } from "../utils/prismaClient";
import { startingForm } from "../utils/startingForm";
Nothing breaks. here, prisma is jsut a new PrismaClient(). Nothing else. In this application I am just using prisma for the getStaticProps of Next.js
However, if I add a index.js to the utils folder and just do:
import { prisma, startingForm } from '../utils"
I get the error again. Is there a reason for this?
You can take a look at the repo here:
https://github.com/itstheandre/build-cv-messing-around
Not a lot of code written. Just a little small thing I was messing around to build a resume and the async_hooks issue came up again. Now I know I am not using prisma on the frontend per se. I am only using it in the api of Next.js. Any idea of what might be happening?
How to reproduce
Expected behavior
Prisma information
Prisma Schema
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Experience {
id Int @default(autoincrement()) @id
name String
company String?
personal Boolean @default(false)
from String?
to String?
description String
website String?
}
Prisma Query -> Literally the only query I am doing
const experiences = await prisma.experience.findMany({})
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Node.js version: 12.16.3
- Prisma version: 2.4.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:26 (12 by maintainers)
A way to get Types in frontend without using
prisma()
:I hit this bug as well. Digging deeper for me the issue was, that I use generated types from @prisma/client quite a lot in the frontend code, which works well enough for type checking. However, when I use an Enum in the frontend code (generated from my prisma schema), then the async_hooks error from above comes up.