Skip to content

prisma is not defined #89

@ignamartinoli

Description

@ignamartinoli

Hi, I was following this tutorial on Nuxt.
I installed Prisma with pnpm dlx nuxi@latest module add @prisma/nuxt and pnpm dlx prisma generate.

This resulted in this package.json:

{
	"name": "nuxt-app",
	"private": true,
	"type": "module",
	"scripts": {
		"build": "nuxt build",
		"dev": "nuxt dev",
		"db:deploy": "pnpm dlx prisma migrate deploy && pnpm prisma generate",
		"generate": "nuxt generate",
		"preview": "nuxt preview",
		"postinstall": "nuxt prepare"
	},
	"dependencies": {
		"@nuxtjs/tailwindcss": "6.13.2",
		"@prisma/client": "6.5.0",
		"@prisma/nuxt": "0.3.0",
		"bcryptjs": "^3.0.2",
		"nuxt": "^3.16.0",
		"vue": "^3.5.13",
		"vue-router": "^4.5.0"
	},
	"devDependencies": {
		"prisma": "6.5.0"
	}
}

After testing an endpoint I receive the error:

ℹ Error: prisma is not defined

 ⁃ at Object.handler (server/api/users.post.js:7:1)

    2 ┃  import bcrypt from 'bcryptjs'
    3 ┃
    4 ┃  export default defineEventHandler(async (event) => {
    5 ┃    const body = await readBody(event)
    6 ┃
 ❯  7 ┃    await prisma.users.create({
    8 ┃      data: {
    9 ┃        email: body.email,
   10 ┃        password: body.password
   11 ┃      }
   12 ┃    })

 ⁃ at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
 ⁃ (async file://node_modules/.pnpm/h3@1.15.1/node_modules/h3/dist/index.mjs:2009:19)
 ⁃ at async Object.callAsync (node_modules/.pnpm/unctx@2.4.1/node_modules/unctx/dist/index.mjs:72:16)
 ⁃ at async Server.toNodeHandle (node_modules/.pnpm/h3@1.15.1/node_modules/h3/dist/index.mjs:2301:7)

[CAUSE]
ReferenceError {
  stack: 'prisma is not defined\n' +
  'at Object.handler (./server/api/users.post.js:7:1)\n' +
  '    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n' +
  'at async file://./node_modules/.pnpm/h3@1.15.1/node_modules/h3/dist/index.mjs:2009:19)\n' +
  'at async Object.callAsync (./node_modules/.pnpm/unctx@2.4.1/node_modules/unctx/dist/index.mjs:72:16)\n' +
  'at async Server.toNodeHandle (./node_modules/.pnpm/h3@1.15.1/node_modules/h3/dist/index.mjs:2301:7)',
  message: 'prisma is not defined',
}

My understanding is that I am not required to manually import Prisma if I'm using this module.
What could be causing this?

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