-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
ImageResponse type error on route after updating to 13.5.1 #55604
Comments
Me too.
|
You should be able to fix that by replacing it with the newly introduced file
You may need to add some segment config at the same time. + export const alt = "Open Graph";
+ export const contentType = "image/png"; |
If you want to use both |
Just in case, replace your Request type with NextRequest like: import type { NextRequest } from 'next/server'
...
export async function GET(request: NextRequest) {
...
} I had the same TS error after updating to 13.5.1 but this fix it. |
What if |
@icyJoseph Isn't this line of documentation the answer for you?
|
@smorimoto nope, because I am generating metadata, where I calculate a special alt tag based of the route. The ImageResponse doesn't accept alt. So I'd have to use the same static alt text. Unless there's a way to export alt as a function that receives the slug, or if I could pass it to the ImageResponse. Even if it's generated on demand, how do we use dynamic parameters from the route when calculating the alt text, that's the question. I'm also still investigating :) |
@icyJoseph Oh, I get it. Try this: generateImageMetadata |
I got it to work just by replacing the import of the ImageResponse from @vercel/og to next/server |
Hey, I don't think this is just related to og images. I'm also seeing this error on a completely different route (and this is only happening after migrating to v 13.5.1). Here's the error on vercel when I'm trying to deploy:
And here's my code:
|
This fixes it, thanks. I just noticed the docs were updated too. |
Hi, can you try to use |
### What? Bump these packages to their latest. (Bumped `satori` too to avoid multiple versions in the repo) ### Why? Follow-up of #55187 ### How? Updated the original package applying the changes from #55187 Closes NEXT-1639 Fixes #55604 [Slack thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1695169119558899)
Upgrading We're also aliasing |
Hi, I'm having the same problem but with the NextResponse...here are a capture of the error message when I run the build command. `⚠ Compiled with warnings ./node_modules/@whatwg-node/fetch/dist/node-ponyfill.js Import trace for requested module: Linting and checking validity of types .Failed to compile. app/api/auth/signup/route.ts Could you help me with this? thanks |
I don't think this is just related to images, either. My API routes were working just fine until I upgraded to
In my route, I'm using both |
Let's open a new issue for these! |
Hey, @balazsorban44, I think there's an open issue for this on #55623 |
That looks slightly different, specifically for |
|
@Revaycolizer @anthonyverducci Not sure if this will help, I was getting the same exact issue on some of my api routes. It came down to the more nested if/then statements in the try/catch. Reducing the number of conditions in the catch seemed to resolve the problem for me. For instance changing: } catch (error) {
const errorMessage = 'An error occured!';
if (error instanceof Error) {
const isDuplicate = error.message.includes(
'Unique constraint failed on the fields: (`username`)',
);
if (isDuplicate) {
return NextResponse.json(
{ message: 'Username is already taken, please try another one' },
{ status: 501 },
);
} else {
return NextResponse.json({ message: errorMessage }, { status: 503 });
}
}
} to this: catch (error) {
const errorMessage =
error instanceof Error
? error.message
: 'An error occured. Please check username and password.';
return NextResponse.json(
{ message: errorMessage, ok: false },
{ status: 503 },
);
} |
But I'm not having any if conditions |
### What #51394 introduced a pretty strict type of return value of route type that causing failure with `next build`. There're few ways of writing a app route, it could contain few return values based on the usage: * return a `Response` or promise of it * return `NextResponse` of promise of it, since it's extended from `Response`, same type * use `redirect()` or `notFound(), since it returns `never`, and the below code is not reached, the handler itself could still return void. e.g. using `redirect` in a `GET` route We loosed the type so `redirect()` can be still allowed without specifying the return value there. Related typescript issue: microsoft/TypeScript#16608 (comment) ### How * Re-enable the bail on types / build error in the app-routes tests * Separate the tests, move runtime erroring ones to `test/e2e/app-dir/app-routes-errors` * Add new case to app-routes tests of mixed return value Closes #55623 Related #55604
We had a fix in 13.5.3, can you try to upgrade to the latest version? Thanks! |
Unfortunately the patch was not a fix, at least not here. I have just upgraded to Next 13.5.3 and linter breaks build with the same error message as with 13.5.1: Type error: Route "src/app/api/frontend/checksession/route.ts" has an invalid export: Double-checked the build after downgrade to 13.4.19: still finishing successfully. For us, it's also unrelated to images. Thank you for investigating! |
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. |
Link to the code that reproduces this issue
https://github.com/Dannymx/shockinglemon.com/tree/develop
To Reproduce
Current vs. Expected behavior
Current:
Expected: no type errors
Verify canary release
Provide environment information
next info Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.6.0: Wed Jul 5 22:21:53 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6020 Binaries: Node: 18.17.1 npm: 9.6.7 Yarn: N/A pnpm: 8.7.5 Relevant Packages: next: 13.5.1 eslint-config-next: 13.5.1 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, TypeScript (plugin, built-in types)
Additional context
This started happening after updating to 13.5.1
NEXT-1639
The text was updated successfully, but these errors were encountered: