Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geist fonts don't work on pages router, only on app router #59

Open
2 tasks done
aryanprince opened this issue Nov 19, 2023 · 9 comments
Open
2 tasks done

Geist fonts don't work on pages router, only on app router #59

aryanprince opened this issue Nov 19, 2023 · 9 comments
Labels
bug Something isn't working where: package The issue corresponds to the distribution package

Comments

@aryanprince
Copy link

aryanprince commented Nov 19, 2023

Font Name (Geist Sans/Geist Mono):

  • Geist Sans
  • Geist Mono

Description of the Issue:

Geist fonts work only on app router but not on pages router. Both Geist Sans and Mono show the following error on pages router:

"SyntaxError: Cannot use import statement outside a module"

Steps to Reproduce:

  1. Create a new Next.js 14 app with pages router
  2. npm i geist@latest and import the font in _app.tsx as docs mention
  3. That's it, you see the error immediately

Pages Router (errors):
Open in StackBlitz

App Router (works fine):
Open in StackBlitz

Expected Behavior:

Geist font should work, as expected, like it does with app router.

Screenshots:

image

Environment:

  • OS: MacOS
  • Software: Using NodeJS runtime and npm as package manager
  • Version of the Font: 1.1.0 (latest at time of writing)

Additional Context:

15+ people from issue #13 faced the same issue mentioned here. But the issue was closed due to a temporary workaround found where adding transpilePackages: ["geist"] in next.config.js fixed the issue. But this fix wasn't documented or mentioned anywhere in docs - nor is it an actual fix for the issue.

StackBlitz links use Next.js 13.5.1, but the issue is the same and persists.

@mwskwong
Copy link

15+ people from issue #13 faced the same issue mentioned here. But the issue was closed due to a temporary workaround found where adding transpilePackages: ["geist"] in next.config.js fixed the issue. But this fix wasn't documented or mentioned anywhere in docs - nor is it an actual fix for the issue.

To add on to this, this is also a valid workaround when trying to import Geist in client components while using Next.js App Router.

I understand this seems to be more relevant tolocalFont itself instead of Geist, but IMO it should be mentioned in the readme.

@aryanprince aryanprince changed the title Geist fonts don't work on pages, only on app router Geist fonts don't work on pages router, only on app router Nov 28, 2023
@sandeshbagade
Copy link

I also had same #13 issue. transpilePackages: ["geist"] in next.config.js worked for me. I wasted half a day playing around with webpack config as I was getting TypeError: next_font_local__WEBPACK_IMPORTED_MODULE_0___default(...) is not a function

I feel this should become the part of official documentation untill gets fixed in next version.

@wayneschuller
Copy link

I tripped over this problem as well - on pages router 14.0.4

@GorvGoyl
Copy link

how ironic that the font developed by vercel is not even fully supported in their own framework. switching back to inter for peace.

@sandeshbagade
Copy link

I wish I could just switch back to inter for peace but PM in my team want Geist :(

@fers4t
Copy link

fers4t commented Jan 7, 2024

same here with all versions of next.js in pages route.

@derfcode
Copy link

Thanks for the temp solution, but yea I hope this gets fully solved.

@stabildev
Copy link

Still an issue in Nextjs 14.2.3 with pages router

@j-fdion
Copy link

j-fdion commented May 14, 2024

Use @sandeshbagade solution.

It worked for me :), thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working where: package The issue corresponds to the distribution package
Projects
None yet
Development

No branches or pull requests

10 participants