When TypeScript error "ts(18004)" occurs, it is because of the object properties within all Prisma DB

I am currently in the process of verifying if a user's email already exists. To achieve this, I am utilizing Prisma Client's findUnique method. Below is the code snippet I have implemented:

const userWithEmail = await prisma.user.findUnique({
    where: {
      email,
    },
  });

However, I encountered a TypeScript error:

No value exists in scope for the shorthand property 'email'. Either declare one or provide an initializer.ts(18004)

Here is my schema.prisma file:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
...

And here is my route.ts file:

import { PrismaClient } from "@prisma/client";
import { NextResponse } from "next/server";
import validator from "validator";
...

I am working with Next.js 13 and Prisma. Can someone please help me identify what I might be doing incorrectly?

Answer №1

It seems like the problem lies in this section:

const body = await request.json();

There is no method request.json(). If you had utilized

import { NextApiRequest } from "next";

TypeScript would have alerted you to this mistake. You should be using NextApiRequest

export interface NextApiRequest extends IncomingMessage {
  query: Partial<{
      [key: string]: string | string[];
  }>;
  cookies: Partial<{
      [key: string]: string;
  }>;
  body: any;
  env: Env;
  preview?: boolean;
  previewData?: PreviewData;
}

Although it extends IncomingMessage, it does not contain a json() property. Instead, you should do

const { email, password } = req.body;

Answer №2

Perhaps the "email" variant is not within the same scope in the method.
For example, if you declare the "email" variant before the findUnique call, this issue will be resolved.

const email = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="661203151226031e070b160a034805090b">[email protected]</a>"
const userWithEmail = await prisma.user.findUnique({
    where: {
      email,
    },
  });

If you do not declare the email variant as "email" (for example, name it mailAddress), try using the following code.

const mailAddress = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e296879196a2879a838f928e87cc818d8d8f">[email protected]</a>"
const userWithEmail = await prisma.user.findUnique({
    where: {
      email: mailAddress,
    },
  });

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

Creating an object type that accommodates the properties of all union type objects, while the values are intersections, involves a unique approach

How can I create a unified object type from multiple object unions, containing all properties but with intersecting values? For example, I want to transform the type { foo: 1 } | { foo: 2; bar: 3 } | { foo: 7; bar: 8 } into the type {foo: 1 | 2 | 7; bar: ...

Successfully resolving the API without encountering any response errors, even after sending a response

Once the data is successfully saved in the database and the image upload is completed, I am attempting to send res.json. However, I keep encountering the error message API resolved without sending a response for /api/auth/registeration, this may result in ...

"Encountering issues with Firebase deployment related to function-builder and handle-builder while working with TypeScript

I encountered 4 errors while executing firebase deploy with firebase cloud functions. The errors are originating from files that I didn't modify. node_modules/firebase-functions/lib/function-builder.d.ts:64:136 - error TS2707: Generic type 'Req ...

I continue to encounter the same error while attempting to deliver data to this form

Encountering an error that says: TypeError: Cannot read properties of null (reading 'persist') useEffect(() => { if (edit) { console.log(item) setValues(item!); } document.body.style.overflow = showModal ? "hidden ...

Using Angular2 - How to pass the router parameter as a variable in ngForm

Struggling to pass a router param (id) to an ngForm and then to an event emitter. I am able to retrieve the id from the router successfully, but when trying to assign it to my singleOpenHome object, I encounter an undefined error: @Input() singleOpenHome: ...

Using Rxjs to dynamically map values from an array with forkJoin

Greetings! I have a collection of Boolean observables and would like to apply a logical AND operation. Currently, I am passing static values 'a' and 'b', but I am unsure of the number of elements in the totalKeys array. import { forkJoi ...

Reactfire encounters import error in Next.js/React application leading to failure

For my Next root layout, I am surrounding the children with the necessary Reactfire providers: import './globals.css'; import { AuthProvider, FirebaseAppProvider } from 'reactfire'; import { auth, firebaseConfig } from '../config/f ...

Asynchronous jQuery operations using promises and finally functionality

I am attempting to interact with a REST api using jQuery's ajax feature. My goal is to return the Promise<Customer> object, but I am encountering an error stating that the property finally is missing. It used to work before, so I assume there h ...

There seems to be an issue with the TypeScript error: it does not recognize the property on the options

I have an item that looks like this: let options = {title: "", buttons: undefined} However, I would like to include a function, such as the following: options.open() {...} TypeScript is giving an error message: property does not exist on the options ty ...

Unlock the full potential of Next.js 13 with Supabase: Discover the best practices for setting up a user context in your application

I am currently developing an app using Next.js 13 and Supabase for the backend. I have been facing a challenge in determining the most effective way to create a context or provider for the logged-in user. The process of retrieving the user from Supabase i ...

searchByTextContentUnderListItemAnchorTag

I would like to utilize the getByRole function for writing my test. However, I am encountering issues when using linkitem or 'link' as the role. It seems that I cannot find the desired element. // encountered error TestingLibraryElementError: The ...

Angular2: Unable to locate the 'environment' namespace

After configuring my tsconfig.json, I can now use short import paths in my code for brevity. This allows me to do things like import { FooService } from 'core' instead of the longer import { FooService } from '../../../core/services/foo/foo. ...

TS2688 Error: TypeScript Build Fails to Locate Type Definition File for 'mocha' Following Update

After updating my TypeScript to the latest version, I keep encountering the following error: Cannot find type definition file for 'mocha'. tsconfig.json { "compilerOptions": { "emitDecoratorMetadata": true, "experimentalDecorators ...

"Error message: Antd datepicker is throwing an error stating that date.clone/date.load is not a

I am working on a React app that has a checkbox to disable a datepicker. However, when I use the checkbox to disable it, I am unable to select any date. If I remove the checkbox and its function, there is no error. Currently, the error message I am getting ...

Arranging information by utilizing arrays

I am working on a component called components.ts in my Angular project. My goal is to create a function that sorts an array based on counts, and then utilize the sorted data in my HTML to generate a chart. import { Component } from '@angular/core&apo ...

Optimizing TypeScript/JavaScript for both browser and Node environments through efficient tree-shaking

I am currently tackling a TypeScript project that includes multiple modules shared between a browser client and a Node-based server. Our goal is to bundle and tree-shake these modules using webpack/rollup for the browser, but this requires configuring the ...

Angular firing off select option with object properties

Within my Angular application, I am faced with a situation involving a <select> element that contains a list of <option> elements whose values are associated with objects. My goal is to capture the last selected value using the following code: ...

Is it recommended to exclude the NGXS NgxsLoggerPluginModule for production deployments?

When developing, it's common to use the following imports: import { NgxsReduxDevtoolsPluginModule } from '@ngxs/devtools-plugin'; import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin'; Is it recommended to remove these imp ...

Implementing NestJS: Integrating TypeORM Datasource without relying on class dependency injection

I have a unique situation that requires some help. Our team is in the process of integrating nestjs into our current express codebase. Previously, we were using Typeorm 0.2 and recently upgraded to 0.3. Due to the fact that we utilize functions instead of ...

I'm having trouble resolving this issue with an Unexpected Application Error! It seems that I cannot set the property value of #<TextFieldBase2> since it only has a

Currently, I'm utilizing TypeScript, React Hook Form, Yup validation, and Fluent UI. Every time I attempt to submit a form, I encounter the error 'Unexpected Application Error! Cannot set property value of # which has only a getter'. https:/ ...