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.
- Creating a custom theme library for various Next.js applications.
- Utilizing buildable libraries to enable incremental building capabilities.
Library | Buildable | Comments |
---|---|---|
providers | No | The Next.js app compiles successfully [with this library](./apps/next-app/src/app/layout.tsx). |
providers-buildable | Yes | The library fails to build successfully due to the font issue. |
To build the Next.js app, run the following commands:
pnpm install
nx build next-app
Notice that the app builds successfully with the Next.js canary version. This is because the application uses the font provider from a non-buildable library and does not import anything from the buildable library.
Run the following commands to build the library:
pnpm install
nx build providers-buildable
Notice that the library imports the "Inter" Google font from "next/font" and observe the error caused by this import.