Next.js Discord

Discord Forum

something really weird, api route cant be found???

Answered
ani posted this in #help-forum
Open in Discord
aniOP
i made a api route and idk why nextjs aint recognizing it?
Answered by ani
const nextConfig = {
  experimental: {
    serverComponentsExternalPackages: ["pdf-parse"],
  },
};


needed to add that experimental
View full answer

16 Replies

aniOP
import { NextResponse } from "next/server";
import { auth } from "@/server/auth";
import { db } from "@/server/db";
import { extractTextFromPDF, processResumeWithAI } from "@/lib/pdf-processor";

export async function POST(req: Request) {
  try {
    const session = await auth();
    if (!session?.user) {
      return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
    }


my api is defined like this too
its just the starting
but nextjs aint cooking it? 💀
( or im doing some dumb mistake ig )
@ani i made a api route and idk why nextjs aint recognizing it?
how do you call your api route?
aniOP
const response = await fetch("/api/process", {
method: "POST",
body: formData,
});
aniOP
yes
@ani yes
hmm. it does not look like to be reproduceable for me. Can you provie a repro for example via github or https://codesandbox.io/ of the issue?
@ani const response = await fetch("/api/process", { method: "POST", body: formData, });
Thanks for sharing your repo. It looks like the api folder process also does not exists. Add the folder and a route the api route will be available
aniOP
oh nope i changed its name check page.tsx
      const response = await fetch("/api/pdf", {
        method: "POST",
        body: formData,
      });
also i found a solution
@ani also i found a solution
what's your solution?
aniOP
const nextConfig = {
  experimental: {
    serverComponentsExternalPackages: ["pdf-parse"],
  },
};


needed to add that experimental
Answer