Skip to content

fix: resolve geist font path for OG images in monorepo#139

Merged
julianbenegas merged 2 commits intomainfrom
forums/fix-og-font-loading-7a418
Feb 7, 2026
Merged

fix: resolve geist font path for OG images in monorepo#139
julianbenegas merged 2 commits intomainfrom
forums/fix-og-font-loading-7a418

Conversation

@julianbenegas
Copy link
Member

The OG image routes were using process.cwd() + node_modules/geist/... to
load font files, which breaks on Vercel in monorepo deployments because
dependencies are hoisted to the workspace root while process.cwd()
points to the app directory (apps/web).

Fix: use createRequire(import.meta.url).resolve() to locate the geist
package dynamically, then resolve font file paths relative to the
resolved package entry. This works regardless of where node_modules
lives in the monorepo.

Extracts font loading into a shared apps/web/app/api/og/fonts.ts
utility used by all OG routes (post, home, repo, user).

The OG image routes were using process.cwd() + node_modules/geist/... to
load font files, which breaks on Vercel in monorepo deployments because
dependencies are hoisted to the workspace root while process.cwd()
points to the app directory (apps/web).

Fix: use createRequire(import.meta.url).resolve() to locate the geist
package dynamically, then resolve font file paths relative to the
resolved package entry. This works regardless of where node_modules
lives in the monorepo.

Extracts font loading into a shared apps/web/app/api/og/fonts.ts
utility used by all OG routes (post, home, repo, user).
@vercel
Copy link
Contributor

vercel bot commented Feb 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
forums Ready Ready Preview, Comment Feb 7, 2026 10:28pm

Turbopack transforms `createRequire().resolve()` into a numeric module
ID at compile time, so the previous approach of resolving font paths via
`require.resolve` failed with 'path must be of type string'.

Instead, vendor the GeistMono Regular and Bold TTF files into
`public/fonts/` and load them via `process.cwd() + public/fonts/...` —
the same proven pattern already used for `public/icon.svg` in the home
OG route.
@julianbenegas julianbenegas merged commit f78b770 into main Feb 7, 2026
4 checks passed
@julianbenegas julianbenegas deleted the forums/fix-og-font-loading-7a418 branch February 7, 2026 22:29
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