-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Route handler returns 404 instead of 200 #58459
Comments
Hi I have fixed the issue please check and review : moroshko/nextjs-pdfmake-issue#1 |
experiencing the same issue |
Same issue here. Trying to use
This is one big WTF. This doesn't brake on import, but when the function call is uncommented. But the function is never called, since the route automatically goes to 404. There is 0 errors whatsoever. I can successfully run the function defined in @Asifdecoder You've literally just removed the function invocation in that PR and you call that a fix? |
Did some more digging and found out that
Which in turn has lead here to this PDFKit issue: bpampuch/pdfmake#2455 Which then leads to a 4 year old webpack example... this is still a bug on Next.js side, as a route compilation failure should not go to a 404, but to fix our problem with |
@moroshko If you're interested I have a working sample for client-side, was going for server-side as it's much easier to get custom fonts done |
Same issue here using
This will return a 404 page on nextjs. However if i remove Let's hope this gets fixed asap. |
I'm getting the same error when I try to call a grpc service client. This is a bizarre error. Please fix this! |
Has anyone gotten this to work? |
This comment has been minimized.
This comment has been minimized.
Anyone has an idea? I'm getting this issue with @project-serum/anchor |
I had same issue with importing pdf-parse package, api routes were returning 404 with no error in the console whatsoever. Finally I thought of trying to 'next build' and then error came up. This is terrible for debugging, why shouldn't those error come up in dev? |
Please how did you fix this, I'm having the same error right now with pdf-parse |
If anyone has figured out how to get past this error in next.js, I would appreciate the info. |
This happens because the package you use, or function throws an error, but Next js does not actually show the error and just returns 200 for some odd reason. Maybe that helps you. |
Hello, sorry for the late reply, just seeing this. |
well yeah express does work. just wonder why next js throws a 200 when theres an error and shows no error. very stupid. |
Haha, the life :) |
Did some digging into this, the reason it happens is that the library throw an error in the module scope, specifically it's a file reading error where // app/api/hello/route.js
const err = new Error("test");
err.code = "ENOENT";
throw err;
export async function GET() {
try {
return Response.json({ message: "ok" });
} catch (error) {
return Response.json({ error: "something went" });
}
} The reason it happens with: import PdfPrinter from "pdfmake";
export async function GET() {
try {
const printer = new PdfPrinter({});
return Response.json({ message: "ok" });
} catch (error) {
return Response.json({ error: "something went" });
}
} But doesn't happen with: import PdfPrinter from "pdfmake";
export async function GET() {
try {
// const printer = new PdfPrinter({});
return Response.json({ message: "ok" });
} catch (error) {
return Response.json({ error: "something went" });
}
} Is that webpack will shake the pdfmake import as it's unused, so the error doesn't happen as the code doesn't run. Because of that another way to reproduce is just logging the package without using it any other way: import PdfPrinter from "pdfmake";
console.log(PdfPrinter)
export async function GET() {
try {
return Response.json({ message: "ok" });
} catch (error) {
return Response.json({ error: "something went" });
}
} Will check with the team what the best way forward is, in some other places the |
Ahhhh, I see... |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I'm currently getting this error and stuck. I can't find a solution. I literally just have this:
export async function POST() {
console.log('paddle webhook');
} I even tried changing it to GET too, but every time I send a request to EDIT: I tried adding a GET handler in there and then opened endpoint in chrome, to my amusement it worked. However, when I tried to send a GET request to the same endpoint using postman, it fails with 404 error. I tried deploying it on vercel, and I can see that hitting the endpoint returns 404 EDIT: Figured it out, it's because of |
i use this code, it's work
|
This solved the issue, thank you! |
Link to the code that reproduces this issue
https://github.com/moroshko/nextjs-pdfmake-issue
To Reproduce
git clone https://github.com/moroshko/nextjs-pdfmake-issue.git
cd nextjs-pdfmake-issue
bun i
bun dev
http://localhost:3000/api/hello
Current vs. Expected behavior
Expected: 200
Actual: 404
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 22.6.0: Fri Sep 15 13:39:52 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_X86_64 Binaries: Node: 18.17.0 npm: 9.6.7 Yarn: 1.22.19 pnpm: N/A Relevant Packages: next: 14.0.3-canary.8 eslint-config-next: 14.0.3-canary.8 react: 18.2.0 react-dom: 18.2.0 typescript: 5.2.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
App Router, Middleware / Edge (API routes, runtime)
Additional context
The following route handler returns a 404 when navigating to
http://localhost:3000/api/hello
:app/api/hello/route.ts
Commenting out
const printer = new PdfPrinter({});
solves the issue (200 is returned, as expected).Here is the 404 response body:
NEXT-3259
The text was updated successfully, but these errors were encountered: