vercel / next.js

The React Framework
https://nextjs.org
MIT License
122.3k stars 26.18k forks source link

Fix: The issue in importing fonts in buildable next.js libraries #66889

Open sooraj-shukla opened 3 days ago

sooraj-shukla commented 3 days ago

What?

In the current canary version of Next.js, importing Next.js fonts in any buildable Next.js library is not supported. Attempting to do so will result in a build failure, with an error indicating that the fonts are not exported from the package. I've created a fresh repository where the issue can be reproduced by following the instructions in the README.

image

Why?

There are following use cases of having a buildable library

  1. Creating a custom theme library for various Next.js applications.
  2. Utilizing buildable libraries to enable incremental building capabilities in monorepos (For example, when using Nx's incremental builds).

How?

The barrel files in next/fonts didn't export the fonts which was the root cause of the issue.

Fixes #51476

ijjk commented 3 days ago

Allow CI Workflow Run

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

sooraj-shukla commented 1 day ago

Could someone please take a look at this small change and suggest me if there is something else that I should do so that this gets merged? It's solving an existing issue in next/font due to which few people are not able to create next.js libraries where using font is required, for example, a theme library.