Next App Router APIs unexpected outputs and Console.log not working
Link to the code that reproduces this issue or a replay of the bug
https://github.com/vlohar08/Nextjs-API-Issue
To Reproduce
- Clone the mentioned Github Repo.
- Run yarn and yarn build
- Start the Nextjs project using yarn start
- Hit this http://localhost:3000/api/auth/google/spreadsheets API using any tool.
Current vs. Expected behavior
Current Behaviour
It returns "NOT OK"
Expected Behaviour Return and Console log the Request.url value
Verify canary release
- [X] I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
Binaries:
Node: 18.16.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 13.4.20-canary.33
eslint-config-next: 13.4.19
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
Additional context
app/api/auth/google/spreadsheets/route.ts
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest) {
try {
console.log(request.url);
return NextResponse.json(request.url);
} catch (error) {
return NextResponse.json("NOT OK");
}
}
No response
It works using latest LTS release of Node. Update Node from 18.2.0 to latest LTS, and try again.
@kddige Tried Node v18.7.1 and Node v20.6.1 but it is still not working and getting the same response.
Am running into a somewhat similar issue where some routes under app/api are swallowing up console.log statements and function returns. Bizarrely, in one of my apps it is only 3 out of six routes.
Hi,
I have a very similar issue:
- If I run
npm run devthe GET endpoint works - If I run
npm run build && npm run startthe GET endpoint does NOT work - If I change the endpoint from GET to POST, it always works!
Example code -- the print is done only with run dev:
export async function GET(_req: NextRequest): Promise<NextResponse>
{
console.log("GET called")
return NextResponse.json({})
}
- Node version: v21.1.0
- Next version: 14.1.0
Regards
Reproducible on my end as well, console logs are being swallowed by the app router api route. Node version: 20.10.0 Next version: 14.2.3
Edit: My api route was "static" because that is the default behavior on the app router side, and as soon as I made it dynamic, the logs started showing up normally like they should. So apparently logs won't show up only if your api route is static.
This issue has been automatically marked as stale due to inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.
This issue has been automatically closed due to inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding!