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

SyntaxError: Cannot use import statement outside a module #13

Closed
1 of 2 tasks
darnfish opened this issue Oct 27, 2023 · 22 comments
Closed
1 of 2 tasks

SyntaxError: Cannot use import statement outside a module #13

darnfish opened this issue Oct 27, 2023 · 22 comments
Labels
bug Something isn't working triaged

Comments

@darnfish
Copy link

Font Name (Geist Sans/Geist Mono):

  • Geist Sans
  • Geist Mono

Description of the Issue:

project_root/node_modules/geist/dist/font.js:1
import localFont from "@next/font/local";
^^^^^^

SyntaxError: Cannot use import statement outside a module

Environment (please complete the following information):

  • OS: macOS

Additional Context:
My package.json does not include type: module

@darnfish darnfish added the bug Something isn't working label Oct 27, 2023
@JohnPhamous
Copy link
Member

@darnfish can you provide a Codesandbox/Replit/repo that repros the problem?

@washedlih
Copy link

have this issue as well

@ckrook
Copy link

ckrook commented Oct 28, 2023

Hello, me to!

@stijnelskens
Copy link

Bump, also having this issue

@ethndotsh
Copy link

me as well

@heyarviind
Copy link

getting same issue

@iamdevmarcos
Copy link

the same issue here

aczw added a commit to scallop-lang/web-platform that referenced this issue Oct 30, 2023
can't use right now because of bug. see vercel/geist-font#13
@aryanprince
Copy link

aryanprince commented Oct 31, 2023

Apparently this error only shows up on pages router. Can someone vouch for this?

I built two new Nextjs 14 apps (app and pages), installed Geist font, and added GeistSans.classNames to _app.tsx and layout.tsx respectively. App router version works fine, pages router one shows the same 'Cannot use import statement outside a module' error.

Link to repos I tested this with: Pages Router (error) & App Router (all good).

Feel free to StackBlitz these since I couldn't get that to work.

@jacobdalamb
Copy link

Also couldn't get Geist package to work in Astro

@dieharders
Copy link

dieharders commented Oct 31, 2023

Same issue. Using "pages" router.

When using import { GeistSans, GeistMono } from 'geist/font' I get the SyntaxError same as OP.
However, when using import localFont from "next/font/local" and then manually downloading fonts into my project is the only way I can load this font without getting the error.

Next.js: v14.0.1
React: v18.2.0
Using PNPM package manager.

@eriksik2
Copy link

Also getting this error on nextjs v13.5.4 with pages router.

@carloscdante
Copy link

carloscdante commented Oct 31, 2023

Also getting this error on Next 13.4.16 w/pages router

@AnimeAllstar
Copy link

AnimeAllstar commented Nov 1, 2023

Me too. Looks like they didn't bother testing it with the pages router.

@JonHMChan
Copy link

Also getting this error with pages

@benjypng
Copy link

benjypng commented Nov 3, 2023

Having this issue with pages router as well.

@enricoros
Copy link

Same - pages router, NextJS 13.4.19 (not updating to13.5/14 because of larger bundle sizes)

@spidgorny
Copy link

This is a fix that worked for me (next.config.js):

transpilePackages: ["geist"],

@kiltedDev
Copy link

kiltedDev commented Nov 8, 2023

This is a fix that worked for me (next.config.js):

transpilePackages: ["geist"],

This fixed it for me as well.

"next": "^13.5.4",
"react": "18.2.0",

using Bun as package manager for this one.

@darnfish
Copy link
Author

darnfish commented Nov 8, 2023

This is a fix that worked for me (next.config.js):

transpilePackages: ["geist"],

Thanks @spidgorny! This worked for me. I had to also add font-sans to my root Tailwind component for the font to actually render, Geist docs makes this kind of difficult to figure out.

@darnfish darnfish closed this as completed Nov 8, 2023
@VapidLinus
Copy link

@darnfish I don't think this issue should be closed.

It's great we found a workaround, but this is still an issue imo until they add this to the installation instructions on the website or the npm page.

@benjypng
Copy link

benjypng commented Nov 9, 2023

@darnfish I don't think this issue should be closed.

It's great we found a workaround, but this is still an issue imo until they add this to the installation instructions on the website or the npm page.

I think so too. It seems like the source of the issue has not been discovered yet.

@aryanprince
Copy link

I made a new issue (#59) with more information about this issue, check it out. Hopefully it gets resolved.

@VapidLinus @hkgnp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triaged
Projects
None yet
Development

No branches or pull requests