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

next/font Roboto_Flex cannot have axis set #72413

Closed
mclement18 opened this issue Nov 6, 2024 · 3 comments · Fixed by #72442
Closed

next/font Roboto_Flex cannot have axis set #72413

mclement18 opened this issue Nov 6, 2024 · 3 comments · Fixed by #72442
Assignees
Labels
bug Issue was opened via the bug report template. Font (next/font) Related to Next.js Font Optimization. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@mclement18
Copy link

Link to the code that reproduces this issue

https://github.com/mclement18/nextjs-font-bug-example

To Reproduce

  1. run the dev server using npm run dev

Current vs. Expected behavior

I expect to be able to use the axes of the Roboto_Flex font since the type signature tells me that I can do it but I get the following error :

`next/font` error:
Axes can only be defined for variable fonts

Provide environment information

Operating System:
  Platform: linux
  Arch: arm64
  Version: #44-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun  7 19:27:11 UTC 2024
  Available memory (MB): 17949
  Available CPU cores: 12
Binaries:
  Node: 22.9.0
  npm: 10.8.3
  Yarn: 1.22.22
  pnpm: 9.12.1
Relevant Packages:
  next: 15.0.3-canary.7 // Latest available version is detected (15.0.3-canary.7).
  eslint-config-next: N/A
  react: 19.0.0-rc-7c8e5e7a-20241101
  react-dom: 19.0.0-rc-7c8e5e7a-20241101
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Font (next/font)

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

It does not work on the 14.2.17 release that we are using on our project.

@mclement18 mclement18 added the bug Issue was opened via the bug report template. label Nov 6, 2024
@github-actions github-actions bot added the Font (next/font) Related to Next.js Font Optimization. label Nov 6, 2024
@samcx
Copy link
Member

samcx commented Nov 7, 2024

@mclement18 Thank you for submitting an issue!

Taking a look at this :frog-eyes:

@samcx samcx self-assigned this Nov 7, 2024
@samcx samcx added the linear: next Confirmed issue that is tracked by the Next.js team. label Nov 7, 2024
@mclement18
Copy link
Author

mclement18 commented Nov 7, 2024

Thank you for your time but I found my mistake. I got confused in the doc at the weight section https://nextjs.org/docs/14/app/api-reference/components/font#weight.

I didn't realized that it was required to set the weight to 'variable' in order to use the axes.

I was trying to do:

const robot_flex = Roboto_Flex({
  variable: '--roboto-flex',
  style: 'normal',
  weight: ['400', '700'], // using an array
  display: 'swap',
  preload: true,
  subsets: ['latin', 'latin-ext', 'greek'],
  axes: ['wdth'],
});

When I had to do:

const robot_flex = Roboto_Flex({
  variable: '--roboto-flex',
  style: 'normal',
  weight: 'variable', // just set it to 'variable`
  display: 'swap',
  preload: true,
  subsets: ['latin', 'latin-ext', 'greek'],
  axes: ['wdth'],
});

I only understood my mistake when I saw this line of code:

if (weights[0] !== 'variable' && axes) {

I guess that I read better code than English 😅

samcx added a commit that referenced this issue Nov 7, 2024
## Why?

The current error message when you have have a set `weight: ['400', '700']` and set `axes: ['wdth']` for a variable font is confusing—it should mention to correct your weight property (e.g., `weight: 'variable'` or nothing at all for `weight`).

- Fixes #72413
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Font (next/font) Related to Next.js Font Optimization. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants