1

I have 3 local fonts in public/fonts path in my Next JS project. When I try to deploy it to Netlify, it fails because it can't resolve modules for fonts.

This is what my layout.js looks like for fonts.

I am using latest NextJS version

 const glacialIndifference = localFont({
 src: [
 {
 path: "../../public/fonts/GlacialIndifference-Regular.otf",
 weight: "400",
 style: "normal",
 },
 {
 path: "../../public/fonts/GlacialIndifference-Italic.otf",
 weight: "400",
 style: "italic",
 },
 {
 path: "../../public/fonts/GlacialIndifference-Bold.otf",
 weight: "700",
 style: "normal",
 },
 ],
 variable: "--font-glacial",
});

This works locally, but fails when building on netlify.

asked Jun 1 at 12:38

2 Answers 2

3

try to make an assets folder outside of public /assets/fonts

and call

@font-face {
 font-family: "Font-name";
 src: url("path/font.otf") format("opentype");
 font-weight: normal;
 font-style: normal;
}
answered Jun 1 at 12:58
Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure if it ́s the same with next.js, but in vite the path needs to be edited. The font is stored in public, but for some reason the path in the font-face needs to be written without public.

Change ../../public/fonts/GlacialIndifference-Regular.otf to ../../fonts/GlacialIndifference-Regular.otf

ShadowCrafter_01
6461 gold badge8 silver badges21 bronze badges
answered Jun 1 at 14:09

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.