How to Fix: Not able to import google font

4 min read

The error happens because Parkinsans is not available in the version of Next.js or the generated next/font/google type definitions currently installed in the project. When you import a Google font from next/font/google, Next.js only exposes supported font exports. If the font is missing from that generated module, TypeScript throws an error like Module ‘next/font/google’ has no exported member ‘Parkinsans’.

Understanding the Root Cause

This issue is usually caused by one of these technical reasons:

  1. The font is not supported by your installed Next.js version. The next/font/google module exposes font functions based on the version of Next.js you have installed. Newer Google fonts may not exist in older releases.
  2. The import name is invalid for your version. Google font names are converted into JavaScript exports. If that export was not generated, TypeScript cannot resolve it.
  3. Outdated type generation or package lock state. Even after updating dependencies, stale node_modules or lockfiles can keep an older font manifest in place.
  4. Using documentation or examples from a newer release. If a font was added after your current version, code copied from examples will fail locally.

In short, this is not usually a problem with your fonts.ts file itself. It is a version compatibility issue between your code and the installed Next.js package.

Step-by-Step Solution

Follow these steps in order.

1. Check your installed Next.js version

Open package.json and inspect the installed version:

{
  "dependencies": {
    "next": "your-version-here",
    "react": "...",
    "react-dom": "..."
  }
}

If you are on an older version, the Parkinsans export may not exist yet.

2. Update Next.js to a version that includes the font

Update your dependencies:

npm install next@latest react@latest react-dom@latest

Or with Yarn:

yarn add next@latest react@latest react-dom@latest

Or with pnpm:

pnpm add next@latest react@latest react-dom@latest

3. Clear cached dependencies if the error remains

If TypeScript still says the export does not exist, remove installed packages and lock artifacts, then reinstall:

rm -rf node_modules .next package-lock.json
npm install

For Yarn:

rm -rf node_modules .next yarn.lock
yarn install

For pnpm:

rm -rf node_modules .next pnpm-lock.yaml
pnpm install

4. Use the font correctly in fonts.ts

Create or update your fonts.ts file:

import { Parkinsans } from "next/font/google";

export const parkinsans = Parkinsans({
  subsets: ["latin"],
  variable: "--font-parkinsans"
});

Then apply it in your app layout:

import "./globals.css";
import { parkinsans } from "./fonts";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body className={parkinsans.variable}>{children}</body>
    </html>
  );
}

5. If the font is still unavailable, use a supported fallback temporarily

This confirms the issue is specifically the missing export and not your setup:

import { Inter } from "next/font/google";

export const inter = Inter({
  subsets: ["latin"]
});

If Inter works but Parkinsans does not, your environment still does not include that font export.

6. Verify against the official Next.js font API documentation

Check the current supported font API in the Next.js font optimization documentation. If the docs show the font but your project does not, your local version is behind.

Common Edge Cases

  • Typo in the import name: Make sure you are using Parkinsans exactly as exported. Even small casing differences break named imports.
  • App Router vs Pages Router confusion: The font API works in both setups, but usage patterns differ. In the App Router, fonts are commonly applied in layout.tsx.
  • TypeScript server cache: Sometimes your editor keeps stale type information. Restart the TypeScript server or reopen the editor after reinstalling dependencies.
  • Monorepo dependency mismatch: In a workspace, one package may reference a different Next.js version than the app actually running.
  • Old lockfile pinning Next.js: Your package.json may say latest-compatible syntax, but the lockfile can still install an older release.
  • Build passes on one machine but fails on another: This usually means the environments are installing different dependency versions.

FAQ

1. Why does TypeScript say the font is not exported even though it exists on Google Fonts?

Because Google Fonts availability and Next.js font export availability are not always identical at the same moment. Next.js must include that font in its own generated font definitions.

2. Can I use the font before Next.js officially exposes it?

Yes. As a temporary workaround, you can self-host the font files or load them manually with traditional CSS, but that bypasses some benefits of next/font such as automatic optimization and privacy-friendly hosting.

3. How do I know whether the issue is my code or my Next.js version?

Replace the import with a well-known supported font like Inter. If that works, your integration is correct and the problem is almost certainly the specific font export not being present in your installed version.

The practical fix is simple: upgrade Next.js, clear stale dependencies, reinstall, and then retry the Parkinsans import. In most cases, that resolves the error immediately.

Leave a Reply

Your email address will not be published. Required fields are marked *