next.js: [NEXT-1102] `opengraph-image` is 404 in route group segments, both image and dynamic
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 20.6.0: Tue Apr 19 21:04:45 PDT 2022; root:xnu-7195.141.29~1/RELEASE_X86_64
Binaries:
Node: 16.19.0
npm: 9.3.1
Yarn: 3.4.1
pnpm: N/A
Relevant packages:
next: 13.3.1-canary.2
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue
https://stackblitz.com/edit/vercel-next-js-k4rkzr?file=app/(group)/segment/page.tsx
To Reproduce
In any Next.JS 13 project, in appDir:
- Create route
(group) - In the route
(group), create a/segment/page.tsx - Create any
/segment/opengraph-image,(jpg|png|...)or(js|jsx|tsx)– doesn’t matter - You won’t be able to access the OG Image for any page in the segment or it’s leaf segments
Describe the Bug
While setting opengraph-image for a segment in the route group, it doesn’t work. You will see a 404 page instead.
It is detected and compiled as evidence by the console messages referring to it:
wait - compiling /opengraph-image.jpg/route (client and server)...
event - compiled successfully in 362 ms (299 modules)
warn - metadata.metadataBase is not set for resolving url "/blog/opengraph-image.jpg?0a4faadd7eacd798", fallbacks to "http://localhost:3000". See https://beta.nextjs.org/docs/api-reference/metadata#metadatabase
Expected Behavior
opengraph-image should work the same on any nesting level, in a route group or outside of a route group.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 7
- Comments: 16 (6 by maintainers)
I may have encountered the same problem, but in a slightly different situation.
Starting point:
Folder structure (app dir): app
Now, when I am trying to access the generated image, I am redirected to the 404 page (as I have a 404 page setup).
Sample access url:
/projekte/neue-app/opengraph-image
When I look at the head tag, I see that the Opengraph image was generated:
The problem seems to be the hash suffix which is added to the URL as already mentioned by @huozhi. It would be cool if there would be a more accessible way to access the generated opengraph images especially for debugging & testing.
I guess this is related : https://github.com/vercel/next.js/issues/48081
Can confirm this is still not fixed in 13.4.8, any
/(routegroup)/in the path for the opengraph-image still returns 404 but does work if you put it outside a route group at the same pathI think I have the same image as this, has anyone found a good workaround?
I tested it with a
canaryand works fine, my setup can be found in issue https://github.com/vercel/next.js/issues/56210@filingroove We’re adding hash suffix for the opengraph-image under group routes now, for my case, If I add an og image I’ll see the url
http://localhost:3000/segment/opengraph-image-2c1y32.jpg?fab2915dd2f098eaasog:imagemetatag value in the/segmentpage.I couldn’t repro the error in the 2nd picture locally with the codesandbox one. Would you mind sharing a repo with which you bumped to this error that having
/blog?