next.js: Next/font does not work with Turbopack in a containerized development environment
Link to the code that reproduces this issue
https://github.com/jmotes/next-font-bug/
To Reproduce
Run these commands to build the image and launch the app:
docker build -t next-font-bug .
docker run -p 3000:3000 next-font-bug
Current vs. Expected behavior
Current behavior:
⚠ [next]/internal/font/google/inter_59dee874.module.css
Error while requesting resource
There was an issue establishing a connection while requesting https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap.
Expected: load up the Google Font correctly.
Provide environment information
Operating System:
Platform: linux
Arch: arm64
Version: #1 SMP Sun Jun 23 23:24:08 UTC 2024
Available memory (MB): 7933
Available CPU cores: 10
Binaries:
Node: 20.14.0
npm: 10.7.0
Yarn: 1.22.22
pnpm: N/A
Relevant Packages:
next: 14.2.4 // Latest available version is detected (14.2.4).
eslint-config-next: 14.2.4
react: 18.3.1
react-dom: 18.3.1
typescript: 5.5.2
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Font (next/font), Turbopack
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
The issue is only reproducible when using next dev --turbo. While setting up the minimal reproduction I noticed that the node:20-alpine image works just fine, however we can also reproduce the issue with a wordpress:php8.2-apache based container too (with Node 20 installed in it), which is where we load up our VS Code Workspace.
This has been mentioned before in issues like https://github.com/vercel/next.js/issues/47802
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 13
- Comments: 16 (2 by maintainers)
stil seeing this with all latest
Getting error using
import { Zen_Kaku_Gothic_New } from 'next/font/google';with tailwind on devcontainers.Yep, +1 on this, recently switched to next/fonts and came up with this issue. Its funny, it doesn’t show any fail reasons:
request to https://fonts.gstatic.com/s/montserrat/v26/JTUSjIg1_i6t8kCHKm459WdhyyTh89ZNpQ.woff2 failed, reason:I have the same problem with docker code-server (An online vscode on a vps) and next 14 or 15, with the turbo.
I’m using Mac and devcontainers
@amdlemos I tried adding it to my docker-compose section for my frontend:
But unfortunately that didn’t work.
I was having a similar problem but without turbopack, when adding google dns to my docker-compose the problem was resolved. Testing this repository I had no problem, but when informing the DNS I noticed that the build time was reduced by 50%.
docker run --dns 8.8.8.8 --dns 8.8.4.4 -p 3000:3000 next-font-bugPosting this here since #68762 was closed as a dupe of this issue.
I just ran into a similar issue using the
with-dockerexample. When building the container, it fails when downloading google fonts:Note though that instead of Node 18, I am using Node 22 in my dockerfile
As a workaound, I’ve changed
FROM node:22-alpine AS basetoFROM node:22 AS basewhich seems to resolve the issue. (also removed theapk addbelow it).https://github.com/vercel/next.js/blob/3da9d70f79a5e46b88ae43ab08af2056bcc388c7/examples/with-docker/Dockerfile#L3 https://github.com/vercel/next.js/blob/3da9d70f79a5e46b88ae43ab08af2056bcc388c7/examples/with-docker/Dockerfile#L8
Could be related to the alpine image, but the
next-font-bugexample mentioned in the first post also doesn’t use alpine. Or it could maybe also be related to ipv6 connectivity? Either way, for the final image, I can still use the alpine variantFROM node:22-alpine AS runner.faced the same problem today out of nowhere. this actually worked
I am using windows and WSL and this is happening as well
I’m on MacOS
Will definitely try this