Error encountered while executing Prisma query with ...WhereInput

While deploying my Next.js app to production via Vercel, I encountered an error related to a Prisma query in one of the API endpoints. The error message states:

Type error: Type '{ activated: true; }' is not assignable to type 'UserWhereInput'.
  Object literal may only specify known properties, and 'activated' does not exist in type 'UserWhereInput'.

I am certain that activated is defined in my schema. How can I resolve this Typescript issue? Below is the code snippet in question:

// ../api/alert.ts

import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "../../lib/prisma";

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  if (req.method === "POST") {
    try {
      const { authorization } = req.headers;

      if (authorization === `Bearer ${process.env.API_SECRET_KEY}`) {
        //make sure the service that is calling this API endpoint is authorized

        //get all users that are activated
        const activeUsers = prisma.user.findMany({
          where: { activated: true },              
        });

        // do other stuff

        res.status(200).json({ success: true });
      } else {
        res.status(401).json({ success: false });
      }
    } catch (err) {
      res.status(500).json({ statusCode: 500 });
    }
  } else {
    res.setHeader("Allow", "POST");
    res.status(405).end("Method Not Allowed");
  }
}

schema.prisma

...
  model User {
  id        String    @id @default(cuid())
  phone     String
  createdAt DateTime  @default(now())
  activated Boolean   @default(false)
  Message   Message[]
}

/lib/prisma.ts

import { PrismaClient } from "@prisma/client";

let prisma: PrismaClient;

if (process.env.NODE_ENV === "production") {
  prisma = new PrismaClient();
} else {
  let globalWithPrisma = global as typeof globalThis & {
    prisma: PrismaClient;
  };
  if (!globalWithPrisma.prisma) {
    globalWithPrisma.prisma = new PrismaClient();
  }
  prisma = globalWithPrisma.prisma;
}

export default prisma;

Answer №1

To ensure proper setup, I included the command prisma generate within the package.json as shown below:

"scripts": {
    "vercel-build": "prisma generate && prisma migrate deploy && next build"
}

Answer №2

Your proposed solution appears to be effective, though there may be some concerns with constantly running migrate deploy during vercel-build.

According to the guidelines provided by Prisma, it is recommended to utilize only prisma generate in the following manner:

{
  ...
  "scripts" {
    "postinstall": "prisma generate"
  }
  ...
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Passing data through services in Angular 2 instead of relying on router parameters

When transferring parameters between components, a common method is to use the following code: onSelect(hero: Hero) { this.router.navigate( ['HeroDetail', { id: hero.id }] ); } However, if the data being passed is complex, using this ap ...

Error in Typescript Observable when using .startWith([])

I encountered the TypeScript error below: Error:(34, 20) TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'number | Scheduler'. Type 'undefined[]' is not assignable to type 'Scheduler& ...

Ways to help a child notice when a parent's variable changes

Looking for help with passing data to a child component? Check out this Plunker: http://plnkr.co/edit/G1EgZ6kQh9rMk3MMtRwA?p=preview @Component({ selector: 'my-app', template: ` <input #x /> <br /> <child [value] ...

Angular 2 module transpilation services

In my angular 2 application, there is a module called common. Here is how the project structure looks like: main --app /common --config //.ts configs for modules --services //angular services --models --store //ngrx store /co ...

Utilize Angular 5/Typescript to extract data from transformed JSON

After successfully retrieving an object using SOAP and HTTPClient from Angular5, I am currently facing challenges when attempting to extract specific values. The issue lies in the fact that I can only access all of them using: import {parseString ...

Exploring the wonders of HTTP requests through pure pipes in Angular 5

I've been working on a pipe that converts currency values from one to another by making an HTTP call. The idea is to pass in the source and destination currencies as parameters. @Pipe({ name: "currencyConverter" }) export class CurrencyConverterP ...

Tips for setting ngModel and name attributes in an angular test for a custom component

Just getting started with angular. I recently developed a custom component that implements the ControlValueAccessor to allow developers to easily access its value. Here's an example of how it can be used: <app-date [label]="'Date 2&apos ...

Can someone guide me on integrating google.visualization typings with Angular CLI?

Currently, I am facing an issue while attempting to utilize Google Charts in a project built with Angular CLI (version 7.2.3). At first, I attempted to install the typings using the command below (both with and without the -dev flag): npm install --sav ...

What is the best way to clear all console output on Windows?

I'm currently working on a NodeJS script that needs to clear the windows console programmatically. I don't want to just slide the console output out of view, but actually erase it completely. The tool I am developing is similar to TypeScript&apo ...

What's the most effective method for adding fields to an enum in Angular, similar to Swift or Kotlin?

Coming from the world of mobile development, I am currently delving into Angular for a new project. I find it quite convenient to add fields to an enum in languages like Swift or Kotlin. For instance, in Swift: enum Status: Int { case connected = 0, di ...

How can I arrange a table in Angular by the value of a specific cell?

Here's the current layout of my table: Status Draft Pending Complete I'm looking for a way to sort these rows based on their values. The code snippet I've been using only allows sorting by clicking on the status header: onCh ...

Clearly defining the data types for static dictionary values, while also deducing the precise structure or at least the keys

My goal is to create a static dictionary that is defined as a single object literal. I want to: Specify the type of values explicitly for typechecks and IDE suggestions Still have the ability to infer the exact shape, or at least keys I can achieve the f ...

Change object properties dynamically to meet requirements in TypeScript

Let's say I have a function that outputs the following: interface result { A?: string; B?: string; C?: string; } When using an array parameter in a function, how can I make certain return parameters non-nullable and required? For example: funct ...

Issues with NPM start arise moments after incorporating create react app typescript into the project

I've encountered an error while trying to initiate my create react app with Typescript. Despite following all the necessary steps, including adding the .env file (with SKIP_PREFLIGHT_CHECK=true) and updating/reinstalling NPM, I keep facing this issue. ...

How to effectively utilize the Angular Material Button individually in a Stackblitz environment?

Most of the time, I rely on Angular Material when working on Stackblitz. Usually, I just import a comprehensive module and everything functions smoothly. However, I recently attempted to solely import the Angular Material Button Module and encountered thi ...

Is there a way to enable intellisense in vscode while editing custom CSS within a material-ui component?

Is there a vscode extension recommendation for intellisense to suggest css-in-js for customized material ui components in .tsx files? For example, I want intellisense to suggest 'backgroundColor' when typing. The closest I found is the 'CSS- ...

Ways to achieve a gradient effect on top of an image

Hey, I'm trying to implement a gradient on images in my project. Here's what I have so far: import Image from 'next/image' import Box from 'mui/material/Box' import PlayIcon from './PlayIcon.tsx' <Box ...

next.js encountered an issue with the product.map function not being recognized

I am trying to retrieve data from a REST API to display on the front end. I have used getStaticProps() for this purpose, but when I try to map the data from the props, it throws an error saying it is not a function. Upon inspection, I found that the data r ...

The functionality to enable the navigation bar dropdown option is malfunctioning

Having an issue with my navBar. Added a navBar with a Dropdown but the option is not working properly. Utilizing the Navbar component from TailWind, the problem lies with the dropdown feature not functioning as expected. https://i.sstatic.net/IZKw9.png ...

Next-auth callbacks are never triggered

With the current configuration of NextAuthConfig (with some parts concealed), the event callbacks.authorized does not seem to trigger. According to the documentation at , there might be a dependency on middleware, but that aspect is not clear to me. Any i ...