英文:
Local fonts fails to resolve in next.js while deploying in vercel
问题
I am trying to use next/fonts
in next.js 13.3
. Everything works fine locally but when I deployed to Vercel, I keep getting this build error Module not found: Can't resolve './fonts/BrFirma-Thin.woff2'
This is what my folder structure looks like
- src
- _app.js
- styles
- font.js
- fonts
_app.js
import { BRFirma } from 'styles/font';
...
<main className={BRFirma.className}>
...
</main>
font.js
import localFont from 'next/font/local';
export const BRFirma = localFont({
src: [
{
path: './fonts/BrFirma-Regular.woff2',
weight: '400',
},
{
path: './fonts/BrFirma-SemiBold.woff2',
weight: '600',
},
],
});
Again I moved the fonts to the public folder just to make sure I am doing it right.
font.js
import localFont from 'next/font/local';
export const BRFirma = localFont({
src: [
{
path: '../../public/assets/fonts/BrFirma-Regular.woff2',
weight: '400',
},
{
path: '../../public/assets/fonts/BrFirma-SemiBold.woff2',
weight: '600',
},
],
});
Once again, everything works fine locally but deployment still fails with the module not found
message.
Just for the record, this is what jsconfig.js
file looks like.
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@/": ["./src/*"]
}
},
"exclude": ["node_modules", "build", "dist", "jest"]
}
(Note: I've removed the HTML entities like <
and "
to provide a cleaner translation of your code.)
英文:
I am trying to use next/fonts
in next.js 13.3
. Everything works fine locally but when I deployed to Vercel, I keep getting this build error Module not found: Can't resolve './fonts/BrFirma-Thin.woff2'
This is what my folder structure looks like
- src
- _app.js
- styles
- font.js
- fonts
_app.js
import { BRFirma } from 'styles/font';
...
<main className={BRFirma.className}>
...
</main>
font.js
import localFont from 'next/font/local';
export const BRFirma = localFont({
src: [
{
path: './fonts/BrFirma-Regular.woff2',
weight: '400',
},
{
path: './fonts/BrFirma-SemiBold.woff2',
weight: '600',
},
],
});
Again I moved the fonts to the public folder just to make sure I am doing it right.
font.js
import localFont from 'next/font/local';
export const BRFirma = localFont({
src: [
{
path: '../../public/assets/fonts/BrFirma-Regular.woff2',
weight: '400',
},
{
path: '../../public/assets/fonts/BrFirma-SemiBold.woff2',
weight: '600',
},
],
});
Once again, everything works fine locally but deployment still fails with the module not found
message.
Just for the record, this is what jsconfig.js
file looks like.
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@/*": ["./src/*"]
}
},
"exclude": ["node_modules", "build", "dist", "jest"]
}
答案1
得分: 1
今天遇到了同样的问题,不太确定为什么 Vercel 不喜欢某些字体,但尝试从不同的地方下载字体文件。您正在使用的路径并不是问题所在。https://github.com/orgs/vercel/discussions/2367
英文:
Ran into the same issue today, not really sure why vercel doesn't like some fonts but try downloading the font file from a different place. the path you're using is not the problem. https://github.com/orgs/vercel/discussions/2367
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论