nextjs - 💡(How to fix) Fix Production Fonts are still trying to be loaded in Development even though code is never hit [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#85614Fetched 2026-04-08 02:14:53
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Participants
Timeline (top)
commented ×1issue_type_added ×1labeled ×1

Error Message

Module not found: Can't resolve './fonts/TTNormsPro/TT_Norms_Pro_Light.woff2'

Code Example

const computeFont = async () => {
  if (process.env.PROPRIETARY_FONT === "TTNormsPro") {
    const { ttNormsPro } = await import("@/styles/fonts");

    return ttNormsPro;
  }

  return devFont;
};

---

## Error Type
Build Error

## Error Message
Module not found: Can't resolve './fonts/TTNormsPro/TT_Norms_Pro_Light.woff2'

## Build Output
src/styles/fonts.ts
Module not found: Can't resolve './fonts/TTNormsPro/TT_Norms_Pro_Light.woff2'

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

Import trace for requested module:
./src/styles/fonts.ts
./src/app/(wca)/layout.tsx

Next.js version: 15.5.6 (Webpack)

---

Operating System:
  Platform: linux
  Arch: x64
  Version: #29~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Aug 14 16:52:50 UTC 2
  Available memory (MB): 32042
  Available CPU cores: 12
Binaries:
  Node: 22.8.0
  npm: 10.8.2
  Yarn: 4.10.3
  pnpm: N/A
Relevant Packages:
  next: 15.5.6
  eslint-config-next: 15.5.6
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: standalone
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/thewca/worldcubeassociation.org/blob/main/next-frontend/src/app/(wca)/layout.tsx

To Reproduce

We have the issue that we have a proprietary production font that can't be checked into the repo due to licensing issue. Even though we have a guard clause not to load the font in development, nextjs still tries to load it and throws an error.

  1. Have a conditional font loading like:
const computeFont = async () => {
  if (process.env.PROPRIETARY_FONT === "TTNormsPro") {
    const { ttNormsPro } = await import("@/styles/fonts");

    return ttNormsPro;
  }

  return devFont;
};
  1. Don't have that font on your local development machine (but don't have that env variable set)
  2. See error
## Error Type
Build Error

## Error Message
Module not found: Can't resolve './fonts/TTNormsPro/TT_Norms_Pro_Light.woff2'

## Build Output
src/styles/fonts.ts
Module not found: Can't resolve './fonts/TTNormsPro/TT_Norms_Pro_Light.woff2'

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

Import trace for requested module:
./src/styles/fonts.ts
./src/app/(wca)/layout.tsx

Next.js version: 15.5.6 (Webpack)

I have also tried to conditionally load the font in the localFont call itself, but it throws an error Font loader values must be explicitly written literals., so you can't circumvent it there either.

Current vs. Expected behavior

Current behavior: Throws an error even if the font shouldn't be loaded. Expected behavior: Don't throw an error if the font code is never evaluated.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #29~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Aug 14 16:52:50 UTC 2
  Available memory (MB): 32042
  Available CPU cores: 12
Binaries:
  Node: 22.8.0
  npm: 10.8.2
  Yarn: 4.10.3
  pnpm: N/A
Relevant Packages:
  next: 15.5.6
  eslint-config-next: 15.5.6
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Font (next/font)

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

No response

extent analysis

TL;DR

  • Consider using a dynamic import with a conditional statement to load the proprietary font only when the environment variable is set.

Guidance

  • Review the computeFont function to ensure it's correctly handling the conditional loading of the font based on the process.env.PROPRIETARY_FONT variable.
  • Verify that the process.env.PROPRIETARY_FONT variable is not set in the local development environment to prevent the font from being loaded.
  • Check if there are any other places in the code where the proprietary font is being imported or loaded without a conditional statement.
  • Consider using a try-catch block to handle the error when the font is not found, to prevent the build from failing.

Example

const computeFont = async () => {
  if (process.env.PROPRIETARY_FONT === "TTNormsPro") {
    try {
      const { ttNormsPro } = await import("@/styles/fonts");
      return ttNormsPro;
    } catch (error) {
      console.error("Error loading proprietary font:", error);
      return devFont;
    }
  }

  return devFont;
};

Notes

  • The issue seems to be related to the way Next.js handles font loading, and the error message suggests that the font is being loaded even when the conditional statement is not met.
  • The provided code snippet and environment information suggest that the issue is specific to the local development environment and the next dev and next build stages.

Recommendation

  • Apply workaround: Use a dynamic import with a conditional statement to load the proprietary font only when the environment variable is set, and handle the error when the font is not found.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING