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

Error: Failed to load font file, Unknown font format when using next/font/local #74071

Closed
milkyfuckinway opened this issue Dec 18, 2024 · 9 comments
Labels
bug Issue was opened via the bug report template. Font (next/font) Related to Next.js Font Optimization.

Comments

@milkyfuckinway
Copy link

Link to the code that reproduces this issue

https://github.com/milkyfuckinway/next-error-unknown-font-format

To Reproduce

  1. Start the application "npm run dev"
  2. Errors "Failed to load font file: (path) Unknown font format" will appear in console

Current vs. Expected behavior

Expect no errors

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Enterprise
  Available memory (MB): 16244
  Available CPU cores: 12
Binaries:
  Node: 23.4.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.1.1 // Latest available version is detected (15.1.1).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.2
Next.js Config:
  output: N/A

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

Font (next/font)

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

next dev (local), next build (local)

Additional context

No response

@milkyfuckinway milkyfuckinway added the bug Issue was opened via the bug report template. label Dec 18, 2024
@github-actions github-actions bot added the Font (next/font) Related to Next.js Font Optimization. label Dec 18, 2024
@milkyfuckinway
Copy link
Author

Fixed with downgrading node from 23 to 22

@LinusDierheimer
Copy link

Is there a fix for people using node 23?

@wesbos
Copy link
Contributor

wesbos commented Dec 20, 2024

this should be opened - having this issue as well

@milkyfuckinway
Copy link
Author

this should be opened - having this issue as well

Done, if tou can please add reproduction link, ive deleted mine, sorry

@wesbos
Copy link
Contributor

wesbos commented Dec 20, 2024

looks to be upstream in fontkit: foliojs/fontkit#356

@jamtycle
Copy link

I am having this issue with bun 1.1.42 and node 23.4.0.
NextJS version: 15.1.2

Trying to load the font using:

import localFont from "next/font/local"; 

export const outfit = localFont({
    src: "../public/fonts/outfit.ttf",
    preload: true,
    variable: "--font-outfit",
});

results in:

Failed to load font file: .../public/fonts/outfit.ttf Error: Unknown font format

Also tried with woff2 files, same error.
Using fonts from "next/gont/google" seems to work.

@xyt-dev
Copy link

xyt-dev commented Dec 25, 2024

This works normally until Node 23.4.0:

const vivo_sans = localFont({
src: [
{ path: "Font/vivoSans-Regular.ttf", weight: '500' },
{ path: "Font/vivoSans-Bold.ttf", weight: '700' },
],
variable: '--font-vivo-sans',
})

Failed to load font file: Font/vivoSans-Bold.ttf
Error: Unknown font format
○ Compiling / ...
The user aborted a request.

Retrying 1/3...
The user aborted a request.

Retrying 1/3...
The user aborted a request.

Retrying 1/3...

<--- Last few GCs --->

[506930:0x5f63b7b4e000] 208231 ms: Scavenge (interleaved) 6435.6 (6444.3) -> 6432.7 (6452.8) MB, pooled: 0 MB, 7.87 / 0.00 ms (average mu = 0.229, current mu = 0.186) allocation failure;
[506930:0x5f63b7b4e000] 209436 ms: Mark-Compact (reduce) 6433.0 (6452.8) -> 6432.4 (6437.9) MB, pooled: 0 MB, 977.83 / 0.00 ms (+ 10.2 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 993 ms) (average mu = 0.24

<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

1: 0x5f639c7edd95 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [next-server (v14.2.15)]
2: 0x5f639ccc1ba4 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [next-server (v14.2.15)]
3: 0x5f639ccc1f79 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [next-server (v14.2.15)]
4: 0x5f639cf0d1bc [next-server (v14.2.15)]
5: 0x5f639cf0d1e4 [next-server (v14.2.15)]
6: 0x5f639cf2453e [next-server (v14.2.15)]
7: 0x5f639cf27744 [next-server (v14.2.15)]
8: 0x5f639d97a667 [next-server (v14.2.15)]

@Shellishack
Copy link

Upgrading to Node v23.5.0 solved this issue for me.

@milkyfuckinway
Copy link
Author

Fixed in Node v23.5.0

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. Font (next/font) Related to Next.js Font Optimization.
Projects
None yet
Development

No branches or pull requests

6 participants