Skip to content

Fix Turbopack compatibility: use asset URL pattern for font#69

Open
vladmdgolam wants to merge 1 commit intoutsuboco:mainfrom
vladmdgolam:fix/font-turbopack-compat
Open

Fix Turbopack compatibility: use asset URL pattern for font#69
vladmdgolam wants to merge 1 commit intoutsuboco:mainfrom
vladmdgolam:fix/font-turbopack-compat

Conversation

@vladmdgolam
Copy link
Copy Markdown

@vladmdgolam vladmdgolam commented Feb 13, 2026

Problem

When using r3f-perf with Next.js + Turbopack, the build fails with:

Code generation for roboto.woff.mjs failed: invalid utf-8 sequence of 1 bytes from index 0

This happens because the original import font from './roboto.woff' causes Turbopack to try parsing the binary font file as UTF-8 JavaScript.

Relates to #59 and #66.

Solution

Use the standard asset URL pattern that all modern bundlers recognize:

// src/roboto-font.ts
const fontUrl = new URL('./roboto.woff', import.meta.url).href
export default fontUrl

This pattern works with Turbopack, webpack 5, and Vite — they resolve the .woff file, copy it to the output, and provide a proper URL at runtime.

Changes

  • src/roboto-font.ts (new) — exports font using new URL() pattern
  • src/components/TextsHighHZ.tsx — imports from ../roboto-font instead of ../roboto.woff
  • src/globals.d.ts — removed declare module '*.woff' (no longer needed since we're not importing .woff files directly)

3 files changed, 8 insertions(+), 3 deletions(-)

Why this pattern?

troika-three-text (used by drei's <Text>) loads fonts via a web worker with an opaque origin. The new URL() pattern ensures the font is accessible via HTTP URL, which works in all environments including web workers.

Test plan

  • pnpm run build succeeds
  • Verified in Next.js 16 + Turbopack — font renders correctly

@vladmdgolam vladmdgolam changed the title Fix Turbopack compatibility: inline font as base64 data URL Fix Turbopack compatibility: use asset URL pattern for font Feb 13, 2026
@vladmdgolam vladmdgolam force-pushed the fix/font-turbopack-compat branch from 8096568 to 85cdbf4 Compare February 13, 2026 12:38
Use standard asset URL pattern (new URL('./roboto.woff', import.meta.url).href)
instead of direct .woff import. This avoids Turbopack incorrectly trying to
parse the binary font file as UTF-8 JavaScript.

Changes:
- Add src/roboto-font.ts exporting font via URL API
- Update TextsHighHZ.tsx to use new font module
- Remove *.woff module declaration (no longer needed since we're not
  directly importing .woff files anymore)

Fixes: utsuboco#59, utsuboco#66
@vladmdgolam vladmdgolam force-pushed the fix/font-turbopack-compat branch from 85cdbf4 to 1c5a2da Compare February 13, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant