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

[turbopack] "Error: invalid type: string" when using variable on next/font #3139

Closed
ZakariaBenali opened this issue Dec 26, 2022 · 4 comments · Fixed by #3505
Closed

[turbopack] "Error: invalid type: string" when using variable on next/font #3139

ZakariaBenali opened this issue Dec 26, 2022 · 4 comments · Fixed by #3505
Labels
kind: bug Something isn't working

Comments

@ZakariaBenali
Copy link

What version of Turbopack are you using?

next: 13.1.1

What package manager are you using / does the bug impact?

pnpm

What operating system are you using?

Linux

Describe the Bug

Using the variable property on next/font with Turbopack causes the following error:
[500] error: invalid type: string "--font-inter", expected a sequence at line 1 column 95

The font is declared as per the docs:

import { Inter } from '@next/font/google'
const inter = Inter({
  subsets:['latin'],
  variable: '--font-inter',
})

Important to note: this only happens when you add the variable property, and you don't have to apply the font style to the app to experience the issue, just declaring the font like so with variable property causes the app to crash.

Expected Behavior

The next/font with variable property works fine without Turbopack.

To Reproduce

  1. Simply create a fresh app using the latest version of next.js (13.1.1 by the time I'm writing this issue).
  2. Declare any google font on _app.tsx as per the doc:
import { Inter } from '@next/font/google'
const inter = Inter({
  subsets:['latin'],
  variable: '--font-inter',
})
  1. Run the app on turbo mode 'pnpm dev --turbo'

Reproduction Repo

No response

@ZakariaBenali ZakariaBenali added area: turbopack kind: bug Something isn't working labels Dec 26, 2022
@pan93412
Copy link

pan93412 commented Jan 15, 2023

I found the exact issue – seems like a wrong declaration? Not sure why the developer declare this as a Vec<T> while specification says that this should be a string: https://nextjs.org/docs/api-reference/next/font#variable

pub variable: Option<Vec<String>>,

Changing variable: 'str' to variable: ['str'] suppress this issue. @ts-expect-error may be needed.

@beldur
Copy link

beldur commented Jan 25, 2023

I have the same issue. Can't use @next/font/google with a variable.

So this documentation breaks with turbopack: https://nextjs.org/docs/api-reference/next/font#css-variables

@jridgewell
Copy link
Contributor

/cc @wbinnssmith

sokra pushed a commit that referenced this issue Jan 27, 2023
Fixes WEB-501

Fixes #3139

This adds proper support for the [`variable`
property](https://nextjs.org/docs/api-reference/next/font#variable) when
constructing fonts. This results in:

* defining a selector in the css module for a classname defining the css
custom property (css variable), whose value is the font family
* adding a `variable` property to the resulting js object whose value is
the classname used in the selector above

Test Plan: Added an integration test.
@minega25
Copy link

Hello There,

Still facing the same issue when setting fonts with tailwindcss according to below instructions: https://nextjs.org/docs/basic-features/font-optimization#with-tailwind-css

jridgewell pushed a commit to vercel/next.js that referenced this issue Mar 10, 2023
…urbo#3505)

Fixes WEB-501

Fixes vercel/turbo#3139

This adds proper support for the [`variable`
property](https://nextjs.org/docs/api-reference/next/font#variable) when
constructing fonts. This results in:

* defining a selector in the css module for a classname defining the css
custom property (css variable), whose value is the font family
* adding a `variable` property to the resulting js object whose value is
the classname used in the selector above

Test Plan: Added an integration test.
sokra pushed a commit to vercel/next.js that referenced this issue Mar 13, 2023
…urbo#3505)

Fixes WEB-501

Fixes vercel/turbo#3139

This adds proper support for the [`variable`
property](https://nextjs.org/docs/api-reference/next/font#variable) when
constructing fonts. This results in:

* defining a selector in the css module for a classname defining the css
custom property (css variable), whose value is the font family
* adding a `variable` property to the resulting js object whose value is
the classname used in the selector above

Test Plan: Added an integration test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants