PrismaClient unsafe any

I keep getting this error. Linter blocks build. So i did create t3 app without prisma then decided to add it later on. ive done theo's tutorial before and never had this issue. and yes ive googled it before and prismaclient unsafe any leads to no related results. Im pretty sure im missing something really obvious but i cant seem to see it.
Solution:
I keep getting this error. Linter blocks build. So i did create t3 app without prisma then decided to add it later on. ive done theo's tutorial before and never had this issue. and yes ive googled it before and prismaclient unsafe any leads to no related results. Im pretty sure im missing something really obvious but i cant seem to see it.
Jump to solution
37 Replies
Not Kevin
Not KevinOP2y ago
@Josh
Josh
Josh2y ago
Aight there has to be more context cause your not importing globalThis Give me the full file
Not Kevin
Not KevinOP2y ago
thats the full file lol and theo's tutorial one is like this
Josh
Josh2y ago
Where are you defining globalThis
Not Kevin
Not KevinOP2y ago
Not Kevin
Not KevinOP2y ago
i have no idea i tried to copy theo's tutorial again let me do a grep so im not definining it anywhere it seems but that line isnt throwing an erroro
Josh
Josh2y ago
Try this
import { PrismaClient } from '@prisma/client';

const globalForPrisma = global as unknown as {
prisma: PrismaClient | undefined;
};

const prisma =
globalForPrisma.prisma ??
new PrismaClient({
log: ['warn'],
});

if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;

export default prisma;
import { PrismaClient } from '@prisma/client';

const globalForPrisma = global as unknown as {
prisma: PrismaClient | undefined;
};

const prisma =
globalForPrisma.prisma ??
new PrismaClient({
log: ['warn'],
});

if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;

export default prisma;
global is an actual keyword, globalThis is not
Not Kevin
Not KevinOP2y ago
ok i tried same issue
Josh
Josh2y ago
Lemme see w/ error
Not Kevin
Not KevinOP2y ago
Not Kevin
Not KevinOP2y ago
Josh
Josh2y ago
What's the big error
Not Kevin
Not KevinOP2y ago
so my theory is that somehow prismaclient constructor returns an any type?
Josh
Josh2y ago
It shouldn't, what I sent is code from my repo that works fine
Not Kevin
Not KevinOP2y ago
yeah so im very confused now lol bc this is a very weird issue which version of prisma client are you using?
Josh
Josh2y ago
I hate to ask but you have a Prisma file and it's installed and etc etc 4.14.1
Not Kevin
Not KevinOP2y ago
yes i do, i did prisma init and all ok same version too
Josh
Josh2y ago
Oh wait send you package json
Not Kevin
Not KevinOP2y ago
"dependencies": {
"@clerk/nextjs": "^4.21.13",
"@prisma/client": "^4.11.0",
"@t3-oss/env-nextjs": "^0.3.1",
"@tanstack/react-query": "^4.29.7",
"@trpc/client": "^10.26.0",
"@trpc/next": "^10.26.0",
"@trpc/react-query": "^10.26.0",
"@trpc/server": "^10.26.0",
"next": "^13.4.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"superjson": "1.12.2",
"zod": "^3.21.4"
},
"devDependencies": {
"@types/eslint": "^8.37.0",
"@types/node": "^18.16.19",
"@types/prettier": "^2.7.2",
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"autoprefixer": "^10.4.14",
"eslint": "^8.40.0",
"eslint-config-next": "^13.4.2",
"postcss": "^8.4.21",
"prettier": "^2.8.8",
"prettier-plugin-tailwindcss": "^0.2.8",
"tailwindcss": "^3.3.0",
"typescript": "^5.0.4"
},
"ct3aMetadata": {
"initVersion": "7.15.0"
}
"dependencies": {
"@clerk/nextjs": "^4.21.13",
"@prisma/client": "^4.11.0",
"@t3-oss/env-nextjs": "^0.3.1",
"@tanstack/react-query": "^4.29.7",
"@trpc/client": "^10.26.0",
"@trpc/next": "^10.26.0",
"@trpc/react-query": "^10.26.0",
"@trpc/server": "^10.26.0",
"next": "^13.4.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"superjson": "1.12.2",
"zod": "^3.21.4"
},
"devDependencies": {
"@types/eslint": "^8.37.0",
"@types/node": "^18.16.19",
"@types/prettier": "^2.7.2",
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"autoprefixer": "^10.4.14",
"eslint": "^8.40.0",
"eslint-config-next": "^13.4.2",
"postcss": "^8.4.21",
"prettier": "^2.8.8",
"prettier-plugin-tailwindcss": "^0.2.8",
"tailwindcss": "^3.3.0",
"typescript": "^5.0.4"
},
"ct3aMetadata": {
"initVersion": "7.15.0"
}
fyi i downgraded from 4.14 bc i wanted to see if that fixed the error
Josh
Josh2y ago
Ahhh Install prisma As dev dep Then restart your vs code
Not Kevin
Not KevinOP2y ago
crap i think what i did was i installed it as a dep no a dev dep im an idiot
Josh
Josh2y ago
No no your missing a package Prisma client is where it should be
Not Kevin
Not KevinOP2y ago
wait no
Josh
Josh2y ago
You also need prisma
Josh
Josh2y ago
Josh
Josh2y ago
See Prisma 4th up from the bottom
Not Kevin
Not KevinOP2y ago
yup i just did that prisma as dev dep prisma client as dep still same error
Josh
Josh2y ago
Did you restart va Vs
Not Kevin
Not KevinOP2y ago
would it be bad if i just ignored this error? yes
Josh
Josh2y ago
Yes Is the repo open source
Not Kevin
Not KevinOP2y ago
its not sadly but i just started so that db.ts file is lterally just that
Josh
Josh2y ago
Hmm
Not Kevin
Not KevinOP2y ago
which is why im extremely confused regarding this error prismaclient constructor shouldnt return an any all the other errors are related to that basically that line is unsafe construction of any type value then the other lines are unsafe assignment of any so if i can solve the constructor issue it should all be resolved
Josh
Josh2y ago
Very weird I still don't see anything wrong
Not Kevin
Not KevinOP2y ago
fuck i know what i did wrong i didnt run prisma generate again oh my god im an idiot sorry for wasting your time lol
Josh
Josh2y ago
That was it? Hahahaha
Not Kevin
Not KevinOP2y ago
i have no idea why i didnt work the first time when i set everything up tho oh well at least i got it to work
Want results from more Discord servers?
Add your server