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)

Most upvoted comments

stil seeing this with all latest

[next]/internal/font/google/zen_kaku_gothic_new_c6217e08.module.css:1304:9
Module not found: Can't resolve '@vercel/turbopack-next/internal/font/google/font'
  1302 |   font-display: swap;
  1303 |   src: url(@vercel/turbopack-next/internal/font/google/font?{%22url%22:%22https://fonts.gstatic.com/s/zenkakugothicnew/v16/gNMVW2drQpDw0GjzrVNFf_valaDBcznOqs9LaWHSSmlNk8rxVYz1keqDognBR0dnbIQ0DZlb2g.25.woff2%22,%22preload%22:false,%22has_size_adjust%22:true}) format('woff2');
> 1304 |   unicode-range: U+7a17-7a19, U+7a1b, U+7a1e-7a21, U+7a27, U+7a2b, U+7a2d, U+7a2f-7a31, U+7a34-7a35, U+7a37-7a3b, U+7a3e, U+7a43-7a49, U+7a4c, U+7a4e, U+7a50, U+7a55-7a57, U+7a59, U+7a5c-7a5d, U+7a5f-7a63, U+7a65, U+7a67, U+7a69-7a6a, U+7a6d, U+7a70, U+7a75, U+7a78-7a79, U+7a7d-7a7e, U+7a80, U+7a82, U+7a84-7a86, U+7a88, U+7a8a-7a8b, U+7a90-7a91, U+7a94-7a98, U+7a9e, U+7aa0, U+7aa3, U+7aa9, U+7aac, U+7ab0, U+7ab3, U+7ab5-7ab6, U+7ab9-7abf, U+7ac3, U+7ac5-7aca, U+7acc-7acf, U+7ad1-7ad3, U+7ad5, U+7ada-7adb, U+7add, U+7adf, U+7ae1-7ae2, U+7ae6-7aed, U+7af0-7af1, U+7af4, U+7af8, U+7afa-7afb, U+7afd-7afe, U+7b02, U+7b04, U+7b06-7b08, U+7b0a-7b0b, U+7b0f, U+7b12, U+7b14, U+7b18-7b19, U+7b1e-7b1f, U+7b23, U+7b25, U+7b27-7b2b, U+7b2d-7b31, U+7b33-7b36, U+7b3b, U+7b3d, U+7b3f-7b41, U+7b45, U+7b47, U+7b4c-7b50, U+7b53, U+7b55, U+7b5d, U+7b60, U+7b64-7b66, U+7b69-7b6a, U+7b6c-7b75, U+7b77, U+7b79-7b7a, U+7b7f, U+7b84, U+7b86, U+7b89, U+7b8d-7b92, U+7b96, U+7b98-7ba0, U+7ba5, U+7bac-7bad, U+7baf-7bb0, U+7bb2, U+7bb4-7bb6, U+7bba-7bbd, U+7bc1-7bc2, U+7bc5-7bc6;
       |         ^
  1305 | }
  1306 | /* [26] */
  1307 | @font-face {

Import map: Resolved by import map


https://nextjs.org/docs/messages/module-not-found

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 wonder if this is a Mac only issue. @jonahallibone @amdlemos what OS’s are you running Docker on?

I’m using Mac and devcontainers

@amdlemos I tried adding it to my docker-compose section for my frontend:

frontend:
    build: .
    env_file:
      - env.list
    dns:
      - 8.8.8.8
      - 8.8.4.4
    volumes:
      - ./frontend/src/:/app/frontend/src/

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-bug

20240709_16h42m33s_grim

Posting this here since #68762 was closed as a dupe of this issue.

I just ran into a similar issue using the with-docker example. When building the container, it fails when downloading google fonts:

1.041    ▲ Next.js 15.2.4
1.050    Creating an optimized production build ...
2.878 Retrying 1/3...
3.159 Retrying 1/3...
3.235 Retrying 2/3...
3.516 Retrying 2/3...
3.746 Retrying 3/3...
3.969 Retrying 3/3...
4.401 [AggregateError: ] { code: 'ETIMEDOUT' }
4.624 [AggregateError: ] { code: 'ETIMEDOUT' }
6.984 Failed to compile.
6.984 src/app/layout.tsx
6.984 `next/font` error:
6.984 Failed to fetch `Rubik` from Google Fonts.
6.984 src/components/catalog/category/CategoryTile.tsx
6.984 `next/font` error:
6.984 Failed to fetch `Rubik` from 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 base to FROM node:22 AS base which seems to resolve the issue. (also removed the apk add below 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-bug example 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 variant FROM node:22-alpine AS runner.

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-bug

20240709_16h42m33s_grim

faced the same problem today out of nowhere. this actually worked

I am using windows and WSL and this is happening as well

I wonder if this is a Mac only issue. @jonahallibone @amdlemos what OS’s are you running Docker on?

I’m on MacOS

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-bug

20240709_16h42m33s_grim

Will definitely try this