-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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.ts files being executed during build #52185
Comments
Note: |
Hello, @davecarlson , i've tested your bug here https://stackblitz.com/edit/github-pawf6k?file=app%2Froute.ts and i cannot reproduce your bug, when i run a build the From what i've seen in the logs on codesandbox, it seems the version installed there is a very old one : It still logs a message asking for feedback on App Router, but this message have been removed since version You may try to reproduce the problem locally or in stackblitz, with the latest version installed. On my end, everything seems to work fine |
Indeed, the lock file shows that you have https://github.com/twilio/twilio-node#environment-variables Based on this, it's also likely that Twilio throws the errors at build time on purpose. |
Please verify that your issue can be recreated with Why was this issue marked with the
|
@balazsorban44 @Fredkiss3 here's a repro of this bug: https://stackblitz.com/edit/stackblitz-starters-utiqwb?file=app%2Froute.js using Next.js 13.4.9 The import { NextResponse } from 'next/dist/server/web/spec-extension/response';
import { redirect } from 'next/navigation';
export async function GET(request) {
try {
const res = await fetch('https://www.google.com', { cache: 'no-store' });
const data = await res.text();
console.log(data);
const url = new URL(request.url);
const { searchParams } = url;
const q = searchParams.get('q') || 'foobar';
console.log(q);
return NextResponse.json({ q });
} catch (e) {
console.log(e);
redirect('https://www.google.com');
}
} Try to If I remove the code which is trying to use import { NextResponse } from 'next/dist/server/web/spec-extension/response';
import { redirect } from 'next/navigation';
export async function GET(request) {
try {
const url = new URL(request.url);
const { searchParams } = url;
const q = searchParams.get('q') || 'foobar';
console.log(q);
return NextResponse.json({ q });
} catch (e) {
console.log(e);
redirect('https://www.google.com');
}
} Then during build, we can see that the catched error is a When using like a temporary file write, the file exists after build: import { NextResponse } from 'next/dist/server/web/spec-extension/response';
import { redirect } from 'next/navigation';
import { writeFile } from 'node:fs/promises';
export async function GET(request) {
try {
await writeFile('tmp.txt', new Date().toISOString(), 'utf-8');
const res = await fetch('https://www.google.com', { cache: 'no-store' });
const data = await res.text();
console.log(data);
const url = new URL(request.url);
const { searchParams } = url;
const q = searchParams.get('q') || 'foobar';
console.log(q);
return NextResponse.json({ q });
} catch (e) {
console.log(e);
redirect('https://www.google.com');
}
} All of this is probably happening because Next.js is trying to pre-render route handlers and when An app router |
I am also having this issue. In my case, it is making it difficult to initialize some packages (like |
In the export const dynamic = "force-dynamic"; Why the |
This issue has been automatically closed because it wasn't verified against next@canary. If you think it was closed by accident, please leave a comment. If you are running into a similar issue, please open a new issue with a reproduction. Thank you. |
@balazsorban44 I updated my repro example to use See more details in my previous comment. This is still in issue. |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:23 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6020 Binaries: Node: 18.16.0 npm: 9.5.1 Yarn: 1.22.19 pnpm: N/A Relevant Packages:r next: 13.4.8 eslint-config-next: 13.4.2 react: 18.2.0 react-dom: 18.2.0 typescript: 4.9.5 Next.js Config: output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue or a replay of the bug
https://codesandbox.io/p/sandbox/cranky-heyrovsky-g5zgpm?file=%2Fapp%2Froute.ts%3A1%2C1
To Reproduce
npm run build
The "username is required" is from the API call to twilio, that should never ever ever be executed at build.
Describe the Bug
When I run
npm run build
, the compiler is attempting to run my route handler. This should not happen. My application ONLY contains route handlers, and no frontend (as it is an API).What this is calling:
This is a webhook, and if this is "Desired behaviour", there needs to be a SIMPLE way to turn it off.
Expected Behavior
The code is compiled, but not exected
Which browser are you using? (if relevant)
n/a
How are you deploying your application? (if relevant)
happens locally
The text was updated successfully, but these errors were encountered: