Skip to content

usePrismaClient() has a type signature of () => any #98

@CodeF53

Description

@CodeF53

steps to reproduce:

  1. make new nuxt project bunx nuxi init
  2. add prisma nuxt bun i @prisma/nuxt and add modules: ["@prisma/nuxt"] to nuxt.config.ts
  3. run client bun dev and approve prisma migrations & the like
  4. add the following to app.vue, and hover client
<script lang="ts" setup>
const client = usePrismaClient()
</script>

it shows loading... for 30s to 3 minutes, then says any

this doesnt make sense because if you ctrl click usePrismaClient after it shows () => any for its type definition, it gives you
const usePrismaClient: typeof import('../../node_modules/@prisma/nuxt/dist/runtime/composables/usePrismaClient')['usePrismaClient']
and if you follow that with ctrl click, you get
export declare const usePrismaClient: () => import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
which if you hover, have a meaningful type signature () => import(".prisma/client").PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>
and all the components of that type signature have reasonable definitions too

so why is the type signature of usePrismaClient () => any?

as further debugging steps I tried:

  • importing usePrismaClient manually
  • using npm instead of bun
  • disabling all my extensions except for the offical nuxtr extension pack
  • copy pasting ./.nuxt/tsconfig.json in its entirety to ./tsconfig.json, I replaced all instances of ./ with ./.nuxt/ and replaced all instances of .. with ., to fix relative pathing following moving the file
  • ran it on another machine
    usePrismaClient is still () => any

I tried testing if it worked on server routes, so I made
server/api/test.ts

export default defineEventHandler(async (event) => {
  return await prisma.user.findMany()
})

prisma is supposed to be auto imported here and it isnt!
If I try importing prisma manually, it says @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again. which is #97

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions