Next.js Discord

Discord Forum

Next/local/font package not working...

Answered
Little yellow ant posted this in #help-forum
Open in Discord
Little yellow antOP
I am trying to use my custom fonts via Next.js/font and using fonts in my stylesheets.

Method to declare fonts in the global.scss and modular scss files:
font-family:var(--GoodTimes-Bold) !important;


font.js to define fonts:
import localFont from 'next/font/local'

const goodTimesRegular = localFont({ src: 'GoodTimesLt-Regular.ttf', variable:"--GoodTimes-Regular"})
const goodTimesBold = localFont({ src: 'GoodTimesRg-Bold.ttf', variable:"--GoodTimes-Bold"})
const proximaNovaRegular = localFont({ src: './ProximaNova-Regular.ttf', variable:"--ProximaNova-Regular"})
const proximaNovaBold = localFont({ src: './ProximaNova-Bold.ttf', variable:"--ProximaNova-Bold"})

export { goodTimesRegular, goodTimesBold, proximaNovaRegular, proximaNovaBold }


_app.js:
<div className={` ${proximaNovaRegular.variable} ${proximaNovaBold.variable} ${goodTimesRegular.variable} ${goodTimesBold.variable}`}>
<Component {...pageProps} />
</div>


What is wrong with the above?
Answered by Ray
const goodTimesRegular = localFont({ src: './GoodTimesLt-Regular.ttf', variable:"--GoodTimes-Regular"})
const goodTimesBold = localFont({ src: './GoodTimesRg-Bold.ttf', variable:"--GoodTimes-Bold"})

maybe the path of the src?
View full answer

12 Replies

What version of nextjs are you using?
@Firelord Ozai What version of nextjs are you using?
Little yellow antOP
13.4.1
The recommended way is adding it in the root layout.tsx file
Little yellow antOP
@Firelord Ozai Can you send a link to the documentation about layout.tsx method?
My response to this post also shows an example: https://nextjs-forum.com/post/1182396893913948200
he is using page router i think
@Ray he is using page router i think
Little yellow antOP
It only works in app router?
no it should work in page router too
const goodTimesRegular = localFont({ src: './GoodTimesLt-Regular.ttf', variable:"--GoodTimes-Regular"})
const goodTimesBold = localFont({ src: './GoodTimesRg-Bold.ttf', variable:"--GoodTimes-Bold"})

maybe the path of the src?
Answer
Little yellow antOP
Yes, missing "./". That was dumb on my part. Thanks.