Skip to content

[Bug] Pre-transform error with next/fonts/google in monorepo package #58

@jcarlson

Description

@jcarlson

Describe the bug

I've setup a monorepo and located all my UI components in a shared package, packages/ui. This includes a utility class for importing fonts with next/font/google at packages/ui/lib/fonts.ts.

On startup, Storybook fails with the following error:

7:13:43 AM [vite] (client) Pre-transform error: Failed to load url
packages/ui/lib/fonts.ts","import":"Inter","arguments":[{"subsets":["latin"],"display":"swap","variable":"--font-
inter"}],"variableName":"inter"} (resolved id: packages/ui/lib/fonts.ts","import":"Inter","arguments":[{"subsets"
["latin"],"display":"swap","variable":"--font-inter"}],"variableName":"inter"}) in /<omitted>/sb-next-vite-
fonts/packages/ui/lib/fonts.ts. Does the file exist?

If I move the fonts.ts file into the same project as Storybook, e.g. at apps/storybook/lib/fonts.ts, then it works as expected.

Steps to reproduce the behavior

  1. git clone https://github.com/jcarlson/sb-next-vite-fonts
  2. cd sb-next-vite-fonts && pnpm install
  3. cd apps/storybook && pnpm run storybook
  4. See error

Expected behavior

Next.js Font optimization should work correctly through library packages.

Environment

  • OS: MacOS 15.6.1
  • Node.js version: v22.19.0
  • PNPM version: v10.11.0

Additional context

Bare bones repository to replicate this issue can be found here:
https://github.com/jcarlson/sb-next-vite-fonts

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions