Skip to content

Build Error for Google Fonts with Spaces on Astro v5.7.7 #13714

@san4d

Description

@san4d

Astro Info

Astro                    v5.7.7
Node                     v20.19.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   server
Adapter                  astro-sst
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Description

When I load a font using fontProviders whose name contains a space (ex. Noto Sans), the project fails to build with an error saying font.unicodeRange?.join is not a function. That appears to be a reference to this line of code.

Example Font Config

In this example, the project builds using Montserrat fine but experiences the issue when I add the Noto Sans font.

import { fontProviders } from 'astro/config'
...
{
    experimental: {
        fonts: [
            {
                provider: fontProviders.google(),
                name: 'Noto Sans',
                cssVariable: '--font-noto-sans',
                styles: ['normal'],
                weights: ['400'],
                fallbacks: ['sans-serif'],
                display: 'block',
            },
            {
                provider: fontProviders.google(),
                name: 'Montserrat',
                cssVariable: '--font-montserrat',
                styles: ['normal'],
                weights: ['200', '400', '500', '600', '700'],
                fallbacks: ['Noto Sans', 'sans-serif'],
                display: 'block',
            },
        ]
}

Stack Trace on Build

font.unicodeRange?.join is not a function
  Location:
.../node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]_lightningc_8530ce986d5918db771865df0baa79e9/node_modules/astro/dist/assets/fonts/utils.js:8:41
  Stack trace:
    at unifontFontFaceDataToProperties (.../node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]_lightningc_8530ce986d5918db771865df0baa79e9/node_modules/astro/dist/assets/fonts/utils.js:8:41)
    at async initialize (.../node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]_lightningc_8530ce986d5918db771865df0baa79e9/node_modules/astro/dist/assets/fonts/vite-plugin-fonts.js:101:17)
    at async _createServer (.../node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/dep-BMIURPaQ.js:38609:20)
    at async syncInternal (.../node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]_lightningc_8530ce986d5918db771865df0baa79e9/node_modules/astro/dist/core/sync/index.js:91:5)
    at async AstroBuilder.run (.../node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]_lightningc_8530ce986d5918db771865df0baa79e9/node_modules/astro/dist/core/build/index.js:184:23)
 ELIFECYCLE  Command failed with exit code 1.

StackBlitz Link

The link shows errors loading the font family in the console that I do not see locally. That said, when I download the project, install dependencies with pnpm, and run the build command, I see the same issue I've described above.

What's the expected result?

I expect the project to build. When I use Astro version v5.7.6, the project builds as expected.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-x9fvudu6?file=astro.config.mjs

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageIssue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions