"Type error: Route "app/api/register/route.ts" has an invalid "POST" export" When building on Vercel
Answered
Asiatic Lion posted this in #help-forum
Asiatic LionOP
Type error: Route "app/api/register/route.ts" has an invalid "POST" export:
Type "{ json: () => any; }" is not a valid type for the function's first argument.
Expected "Request | NextRequest", got "{ json: () => any; }".
Error: Command "npm run build" exited with 1import bcrypt from "bcryptjs";
import { PrismaClient } from "@prisma/client";
import { NextResponse } from 'next/server';
const prisma = new PrismaClient();
export async function POST(request: { json: () => any; }){
const body = await request.json();
const { name, email, password } = body.data;
if(!name || !email || !password) {
return new NextResponse('Missing name, email, or password', { status: 400 })
}
const exist = await prisma.user.findUnique({
where: {
email: email
}
});
if(exist) {
throw new NextResponse('User already exists', { status: 400});
}
const hashedPassword = await bcrypt.hash(password, 10);
const user = await prisma.user.create({
data: {
name,
email,
hashedPassword
}
});
return NextResponse.json(user);
}Do you guys have any idea how to solve this? I don't understand what does this mean and i found nothing on google/chatgpt
Answered by B33fb0n3
You need to replace your request object (first argument) to the correct type:
You need to do
... POST(request: { json: () => any; }){ ...You need to do
... POST(request: NextRequest){ ...15 Replies
@Asiatic Lion your request object (first argument):
must be either
... POST(request: { json: () => any; }){ ...must be either
Request or NextRequest. You can still get the json from it, if you using the correct type and the error is also resolved when using the correct type@B33fb0n3 <@760653894048546868> your request object (first argument):
tsx
... POST(request: { json: () => any; }){ ...
must be either ``Request`` or ``NextRequest``. You can still get the json from it, if you using the correct type and the error is also resolved when using the correct type
Asiatic LionOP
How can i do that?
*How should
Asiatic LionOP
You mean i have to put the request with capital R?
@Asiatic Lion You mean i have to put the request with capital R?
You need to replace your request object (first argument) to the correct type:
You need to do
... POST(request: { json: () => any; }){ ...You need to do
... POST(request: NextRequest){ ...Answer
Type error: Object literal may only specify known properties, and 'hashedPassword' does not exist in type '(Without<UserCreateInput, UserUncheckedCreateInput> & UserUncheckedCreateInput) | (Without<...> & UserCreateInput)'.
30 | name,
31 | email,
> 32 | hashedPassword
| ^
33 | }
34 | });At this part :
const hashedPassword = await bcrypt.hash(password, 10);
const user = await prisma.user.create({
data: {
name,
email,
hashedPassword
}
});And this :
./node_modules/bcryptjs/dist/bcrypt.js
A Node.js API is used (process.nextTick at line: 352) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime
Import trace for requested module:
./node_modules/bcryptjs/dist/bcrypt.js
./auth.config.ts@Asiatic Lion tsx
Type error: Object literal may only specify known properties, and 'hashedPassword' does not exist in type '(Without<UserCreateInput, UserUncheckedCreateInput> & UserUncheckedCreateInput) | (Without<...> & UserCreateInput)'.
30 | name,
31 | email,
> 32 | hashedPassword
| ^
33 | }
34 | });
Asiatic LionOP
I really cant understand what does this mean
And i do prisma generate :
"scripts": {
"dev": "next dev",
"build": "prisma generate && next build",
"start": "next start",
"lint": "next lint"
},@Asiatic Lion I really cant understand what does this mean
Himalayan
It means that "hashedPassword" doesnt exist on your user model can you show it from your prisma schema?
Yea, share your user model pls