next.js: Error 'Failed to fetch `Noto Sans JP` from Google Fonts.'
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: Ubuntu 20.04.0 LTS Fri Jan 20 2023 09:56:57 GMT+0000 (Greenwich Mean Time)
Binaries:
Node: 16.14.2
npm: 7.17.0
Yarn: 1.22.19
pnpm: 7.13.6
Relevant packages:
next: 13.1.3
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
Font optimization (@next/font)
Link to the code that reproduces this issue
https://stackblitz.com/edit/nextjs-qcjltu?file=app%2Fpage.js,package.json
To Reproduce
To reproduce, run npm run build
.
Describe the Bug
Font input is
import { Noto_Sans_JP } from '@next/font/google';
const notoSansJapanese = Noto_Sans_JP({
weight: '400',
preload: false,
});
results in
Failed to compile.
app/page.js
`@next/font` error:
Failed to fetch `Noto Sans JP` from Google Fonts.
Possibly related to https://github.com/vercel/next.js/pull/44594 and https://github.com/vercel/next.js/commit/5f2c9d0b301588cec60c3bfb6b36cb7ece787659
Expected Behavior
Compiles successfully.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 42
- Comments: 82 (6 by maintainers)
Commits related to this issue
- refactor: ♻️ (`family.font.ts`) フォントファイルのローカルでのホストをやめて、Google Fontsを利用するようにした。 https://github.com/vercel/next.js/issues/45080 この問題を避けるために、現在一部ワークアラウンドが必要です。 — committed to astronomy-club-at-nitic/nitic-astronomy by ReoHakase a year ago
- Add retries and clear message to font fetching (#51890) Improve the problems mentioned in #45080. - Adding error retries (3 attempts) to font fetching. When you have a slow network, it might take >3... — committed to vercel/next.js by shuding a year ago
Removing the
.next
directory fixed the problem for me.This issue will be fixed #51890. We now have retry logic when this fails, CLI errors that tell you about unstable network, and it’s no longer depending on
AbortController
.Let us know if you have other suggestions!
Upgrading Node version
14.x
to18.x
inside the Vercel’sSettings > Node.js Version
fixed this for me.https://github.com/vercel/next.js/issues/45080#issuecomment-1485398172 Looks like this is the cause🤔
After I directly modified the timeout from original
3000
to sufficient30000
in the file noted in the error stack, it could fetch from Google Fonts successfully. However of course, this is only a temporal solution since you need to edit a file insidenode_modules
directly.IMHO, the original timeout setting (
3000
) is too short for especially CJK fonts, which have relatively larger file sizes. Any improvement towards this would be so appriciated🥺P.S. Please upvote this idea🙏 https://github.com/vercel/next.js/discussions/47009
Possible Temporal Fix
In my case, I have editted
/Users/ReoHakase/repos/nitic-astronomy/node_modules/.pnpm/next@13.3.4_@babel+core@7.21.4_react-dom@18.2.0_react@18.2.0_sass@1.62.1/node_modules/next/dist/compiled/@next/font/dist/google/fetch-font-file.js
as shown in the followind code:My environment
Mmm… maybe it’s a issue with the node version? When running
npm run dev
after removing the.next
folder, I get this error:Looking for AbortController, I’ve found that node includes it since
15.0.0
and I’m using14.21.1
. Which version are you all using?Im located in Russia and got this error. Fixed by using VPN.
As mentioned upgrading node version then removing
.next
folder. Fixed the issue for me.there is abortController in fetch-font-file. in dev mode it use timeout 3000. consider more timeout or none?
I was also struggling with this issue recently. In my case, the error was:
This started to occur on next version >= 13.2.4. In my case, downgrading to next 13.2.3 solved the issue. Removing
.next
folder or using different version ofnode
did not help. Not sure what is the root cause of this, however hopefully it will be resolved in later versions of nextjs.Can confirm. After updating from
13.2.3
to13.2.4
the build breaks on vercel: Same error as in https://github.com/vercel/next.js/issues/45080#issuecomment-1467584677 The issue was fixed with updating from 14.x to 18.x (16.x also works) Here is my code:For anyone facing the issue on vercel make sure the Node Version is set to a newer version than 14.x (like 16.x and 18.x) in the project settings:
CSS files provided by Google Fonts (https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400&display=swap) have woff2 files split by unicode ranges. Downloading otf files and using
@next/font/local
is not an option for CJK.Have the same issue with default create-next-app skeleton.
Seems like a SSL related error. Running
npx next dev
/npx next build
withNODE_TLS_REJECT_UNAUTHORIZED=0
, but you should use it at your own risk. It’s effectively disable SSL certificate validation ⚠️.I am getting the Same Error on NodeJS v18.16.0 (LTS) with Next.js v13.3.1
@emmgfx are you using Node v14 by any chance? It was happening for us till yesterday. I tried with Node v16 and it worked like a charm!
Hello,
Any news on this? I still have this issue on next v13.4.4. I am on node v18.16.0 I have also deleted the .next folder. The error I get is:
The error looks intermittent so might not be permanently fixed for anyone. Could be some rate limiting or timeout.
I’ve upgraded Node to 18.x by Nvm, it worked.
I was running v18 and this was happening as well, so I wouldn’t advise upgrading too far up until this is fixed. I’m now using v14 and the problem is gone.
Another workaround is downloading the fonts manually and using
@next/font/local
.### for me, this worked set preload:false
I just encounter the same issues with version 13.4.5 and I added this solution
preload: false
and it works fine for me. I’m using a Mac, Nodejs v16.15.1, Hope this helps anyone facing the same issuesIt appears to me that it is caused by issue in node-fetch when there are a large amount of font files to fetch.
node-fetch/node-fetch#1735
I have a font config requiring me to download 404 font files which makes it impossible for me to build the project successfully. The error is gone when I reduce the files required to 101.
The code below is fetching all the font files at nearly the same time. I can build successfully with 404 font files after I changed
Promise.all
to fetching sequentially.https://github.com/vercel/next.js/blob/22ea7d99095cee37b327c5c674a78d893b95d38c/packages/font/src/google/loader.ts#LL106C1-L140C6
Hope nextjs team can consider batching the requests here to avoid this issue
GitHub Actions often have network issues on GitHub hosted runners, so I published an action to address that. I don’t expect that to reduce the failure rate to completely zero, but the rate should drop significantly. https://github.com/smorimoto/tune-github-hosted-runner-network
I was getting the same error, you just need to update your node version to lts or 15+ and delete .next folder.
Can you update your Next? Since 13.2 I think that
@next/font
isn’t required, you should usenext/font
. Check this.For me, I was using v14 and then I changed it to v16. It has solved my problem.
The error happens with other fonts such as
Roboto
: https://stackblitz.com/edit/nextjs-xxuvuq?file=app/page.jsSo Next js 13.4.13 recommends variable fonts for better optimization so after reading the the documentation I got the solution so in Poppins font weight prop is required and subsets is required when preload is set to true. So in weight prop you can only add two weight sizes as weight: ‘100 900’ for a variable font.
for further check out the docs : https://nextjs.org/docs/pages/api-reference/components/font
This worked for me !!
this answer worked for me https://stackoverflow.com/questions/76478043/next-js-always-fail-at-downloading-fonts-from-google-fonts
Here is how i managed to fix:
nvm install --lts
nvm use --lts
.next
folderDone. Now i can run
npm run dev
without any errors.works for me. thanks 😃
I have the same issue with
next@13.4.3
(current latest) and Node.js18.16.0
(current LTS).I’m currently based in China and use a VPN. I suppose that the fetching from the
next/font
package is failing because of that. Even though I successfully can reach the fetching URL (in my case:https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@200;300;400;600;700;900&display=swap
) from the browser. It works well once built and started. It only does not work when running the development server.As a temporary fix I directly imported the Google stylesheet and removed the config related to
next/font
. Also, I deleted the.next
folder and rerun the development server vianpm run dev
.It is not ideal, but will do for now. Hope the team will take a closer look at the issue 🙏
Before
app/layout.tsx
After
app/layout.tsx
Hope that helps.
I had a similar issue, I can’t remember because I’ve been working on a React native module recently, but I think it was because I had @next/font installed and using it. Migrating to next/font as recommended by next seems to have fixed it. At least for now.
And It’s Solved the Error!
I have the same problem with node v18.12.1, next 13.1.5, @next/font: 13.1.5. deleting
.next
folder not work for me.I had the same problem with node v16.19.0, deleting the
.next
folder solved it. I didn’t upgrade the node version.I am on
18.3.0
. Seems like an SSL error as bazhenov said, asNODE_TLS_REJECT_UNAUTHORIZED=0
is the only thing that helpsEdit: for some reason, error is back - even with the flag (which still helps in
npm run build
tho)I’ve stumbled on this issue again after updating
next
to13.2.3
, and removing.next
did fix the problem.Here is my code, which, I suspect, should not be too different from anyone still having the problem:
So the other files than
_app.tsx
might be affecting I guess?Hmm. The problem still occurs for me after removing
.next
.@Shahzad6077 I just added font
<link/>
s into<head/>
as instructed by Google Fonts.It looks like
fetchFontFile
function is failing with an error: https://github.com/vercel/next.js/blob/ac0b6d2a719fd6656b555dc398e73c01c71feae4/packages/font/src/google/utils.ts#L258I can access the URL via the browser/curl, so I think it’s not the internet connection issue.