next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Could not use relative URLs with "next/font"

Open HalfLegend opened this issue 1 year ago • 22 comments

Verify canary release

  • [X] I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 11 Enterprise
    Binaries:
      Node: 20.3.1
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.4.8-canary.13
      eslint-config-next: 13.4.7
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: export

Which area(s) of Next.js are affected? (leave empty if unsure)

Font optimization (next/font)

Link to the code that reproduces this issue or a replay of the bug

npx create-next-app

To Reproduce

I want to export my pages using relative URL's like:

href="_next/static/...."

I am using the solution here: https://github.com/vercel/next.js/issues/2581

I am using the basic project created by create-next-app without Tailwind CSS. (Every option in create-next-app is default except for Tailwind CSS )

Here is my next.config.js:

const nextConfig = {
    output: 'export',
    assetPrefix: './'
}
module.exports = nextConfig

When I run "next build", an error occurs:

app\layout.tsx
`next/font` error:
assetPrefix must start with a leading slash or be an absolute URL(http:// or https://)

Describe the Bug

If I comment everything related to "next/font" in "app\layout.tsx"

import './globals.css'
// import { Inter } from 'next/font/google'

// const inter = Inter({ subsets: ['latin'] })

export const metadata = {
  title: 'Create Next App',
  description: 'Generated by create next app',
}

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      {/*<body className={inter.className}>{children}</body>*/}
      <body>{children}</body>
    </html>
  )
}

Everything works fine.

So the bug is with next/font module.

Expected Behavior

"next/font" should support a relative path in assetPrefix like "./"

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

HalfLegend avatar Jun 30 '23 17:06 HalfLegend