Skip to content
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

Importing local font in edge runtime is broken since Next 15 with pages router (vercel/og example) #74385

Open
chemicalkosek opened this issue Dec 29, 2024 · 1 comment
Labels
bug Issue was opened via the bug report template. Pages Router Related to Pages Router. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@chemicalkosek
Copy link
Contributor

chemicalkosek commented Dec 29, 2024

Link to the code that reproduces this issue

https://github.com/chemicalkosek/og-reproduction

To Reproduce

  1. Start the app in dev mode npm run dev
  2. Visit http://localhost:3000/api/og
  3. See error:
 ⨯ Error [TypeError]: fetch failed
    at handler (pages/api/og.js:11:25)
   9 |
  10 | export default async function handler() {
> 11 |   const fontData = await fetch(
     |                         ^
  12 |     new URL('./og/lexend-deca-v21-latin_latin-ext-700.ttf', import.meta.url),
  13 |   ).then((res) => res.arrayBuffer());
  14 |

Current vs. Expected behavior

Current behavior: Og generation fails with a fetch error while importing local file

Expected behavior: It should generate og with custom font. This is working with Next 14
I didn't see any breaking changes in Next 15 that could cause this.
The code also comes from the official example: https://vercel.com/guides/using-custom-font

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #52-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec  5 13:09:44 UTC 2024
  Available memory (MB): 27914
  Available CPU cores: 16
Binaries:
  Node: 22.12.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.1.1-canary.23 // Latest available version is detected (15.1.1-canary.23).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Pages Router, Runtime

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

No response

@chemicalkosek chemicalkosek added the bug Issue was opened via the bug report template. label Dec 29, 2024
@github-actions github-actions bot added Pages Router Related to Pages Router. Runtime Related to Node.js or Edge Runtime with Next.js. labels Dec 29, 2024
@baraich
Copy link

baraich commented Jan 6, 2025

@chemicalkosek

There's an issue with the current approach for handling the font files.
Moving the og folder from api to public and updating the fontData retrieval method will resolve this.

Filesystem Changes

image

Code changes

Here's the suggested code modification:

// /api/og.js
const fontData = await fetch(
  new URL(
    "./og/lexend-deca-v21-latin_latin-ext-700.ttf",
    req.url.substring(0, req.url.lastIndexOf("/api"))
  )
).then(res => res.arrayBuffer());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Pages Router Related to Pages Router. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

2 participants