N
Nuxt2w ago
Adam

Font not loading on production build

Hey! Recently almost finished my focus-centered clock app. I was deploying a beta version on my domain, but came across an issue: the font file doesn't load for the icons. I use nerdfont's webfont.css file (that I downloaded and adapted for my setup, changing the reference to the font file accordingly to ~/assets/fonts/Symbols-2048-em Nerd Font Complete.woff2). You can see the whole code here: https://github.com/TheDogHusky/home-clock Here is what happens: after the build, I can see the nerdfonts webfont css being loaded in the website in a style element:
<style>
@font-face{font-family:NerdFontsSymbols Nerd Font;font-style:normal;font-weight:400;src:url(/_nuxt/Symbols-2048-em Nerd Font Complete.QenJOl56.woff2) format("woff2")}.nerd-font,.nerd-fonts,.nf{font-family:NerdFontsSymbols Nerd Font;font-style:normal;font-variant:normal;font-weight:400;line-height:1;text-transform:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.nf-cod-account:before{content:""}/* and so on.. */
</style>
<style>
@font-face{font-family:NerdFontsSymbols Nerd Font;font-style:normal;font-weight:400;src:url(/_nuxt/Symbols-2048-em Nerd Font Complete.QenJOl56.woff2) format("woff2")}.nerd-font,.nerd-fonts,.nf{font-family:NerdFontsSymbols Nerd Font;font-style:normal;font-variant:normal;font-weight:400;line-height:1;text-transform:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.nf-cod-account:before{content:""}/* and so on.. */
</style>
As you can see here, the src has been changed to nuxt's built stuff url _nuxt. If I manually navigate to https://my.domain.com/_nuxt/Symbols-2048-em Nerd Font Complete.QenJOl56.woff2, I get the file. However on the website, there is not a single web request made to load that font. Therefore, it is not there and the icons doesn't work. Surprinsingly, I've made this setup work before on another of my project, using the same way: downloading webfont.css, renaming it to nerdfonts.css, putting it in ~/assets/css/nerdfonts.css and downloading the font to ~/assets/css/fonts/<font> while changing the path to the font in the css file. The font works in dev, it only fails after nuxt build and running the server. Any ideas?
8 Replies
kapa.ai
kapa.ai2w ago
Hi @Adam. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information in the knowledge sources, here are some key points and suggestions for your issue: 1. How Nuxt Handles Assets
- Files in the assets/ directory are processed by the build tool (Vite or webpack) and are not directly served at a static URL. Instead, they are bundled and their URLs may be rewritten (e.g., to /_nuxt/filename.hash.woff2).
- If you need a file to be available at a static URL, you should place it in the public/ directory, not assets/Nuxt Assets Documentation. 2. Font Loading in Production
- In development, assets in assets/ are served directly, which is why your font works. In production, Nuxt processes and hashes these files, and the URLs are rewritten.
- If your CSS references a font using a relative path (e.g., url(./fonts/filename.woff2)), Nuxt will rewrite this to a hashed path under /_nuxt/.
- If the font is not being requested by the browser, it could be due to a path issue or the way the CSS is being injected. 3. Recommended Solution
- Move your font files to the public/ directory (e.g., public/fonts/Symbols-2048-em Nerd Font Complete.woff2).
- Update your CSS to reference the font using an absolute path:
@font-face {
font-family: 'NerdFontsSymbols Nerd Font';
src: url('/fonts/Symbols-2048-em Nerd Font Complete.woff2') format('woff2');
font-weight: 400;
font-style: normal;
}

@font-face {
font-family: 'NerdFontsSymbols Nerd Font';
src: url('/fonts/Symbols-2048-em Nerd Font Complete.woff2') format('woff2');
font-weight: 400;
font-style: normal;
}

- This ensures the font is always available at /fonts/... in both development and production, and avoids issues with asset hashing and rewriting. 4. Additional Notes
- The Nuxt documentation specifically recommends placing local font files in the public/ directory and referencing them with an absolute path in your CSS for reliable production buildsNuxt Styling Documentation. If you follow this approach and update your references, your font should load correctly in production. If you are still experiencing issues after this, please check the browser's network tab for any failed requests or MIME type errors, and ensure there are no typos in the file paths. Let me know if you need further clarification! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@662227196814819349> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Adam
AdamOP2w ago
trying out putting it in the public folder, makes sense.
kapa.ai
kapa.ai2w ago
Let me check the knowledge base for you again. One moment! :books: Sorry @Adam, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Adam
AdamOP2w ago
@kapa.ai Well now there is some relevant information:
/fonts/Symbols-2048-em Nerd Font Complete.woff2 referenced in /fonts/Symbols-2048-em Nerd Font Complete.woff2 didn't resolve at build time, it will remain unchanged to be resolved at runtime
ℹ ✓ 162 modules transformed.

ERROR ✗ Build failed in 22.21s
[nuxi] ERROR Nuxt Build Error: [nuxt:fonts:font-family-injection] fetch failed
/fonts/Symbols-2048-em Nerd Font Complete.woff2 referenced in /fonts/Symbols-2048-em Nerd Font Complete.woff2 didn't resolve at build time, it will remain unchanged to be resolved at runtime
ℹ ✓ 162 modules transformed.

ERROR ✗ Build failed in 22.21s
[nuxi] ERROR Nuxt Build Error: [nuxt:fonts:font-family-injection] fetch failed
src:url("/fonts/Symbols-2048-em Nerd Font Complete.woff2") format("woff2")
src:url("/fonts/Symbols-2048-em Nerd Font Complete.woff2") format("woff2")
kapa.ai
kapa.ai2w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The error message you’re seeing:
/fonts/Symbols-2048-em Nerd Font Complete.woff2 referenced in /fonts/Symbols-2048-em Nerd Font Complete.woff2 didn't resolve at build time, it will remain unchanged to be resolved at runtime
...
[nuxt:fonts:font-family-injection] fetch failed
/fonts/Symbols-2048-em Nerd Font Complete.woff2 referenced in /fonts/Symbols-2048-em Nerd Font Complete.woff2 didn't resolve at build time, it will remain unchanged to be resolved at runtime
...
[nuxt:fonts:font-family-injection] fetch failed
suggests that Nuxt (or the @nuxt/fonts module) is unable to resolve or process your font file during the build. Key points from the knowledge sources: - Fonts in public/: Nuxt recommends placing local font files in the public/ directory and referencing them with an absolute path in your CSS, e.g. url('/fonts/your-font.woff2'). This ensures the file is available at build and runtime, and avoids issues with asset processing or hashing.
See: Nuxt Styling Documentation - Fonts in assets/: Files in assets/ are processed by the build tool and are not available at a static URL. If you reference them with an absolute path, Nuxt may not be able to resolve them at build time, leading to the error you see.
See: Nuxt Assets Documentation - @nuxt/fonts module: If you are using Nuxt UI, it automatically registers the @nuxt/fonts module, which tries to optimize font loading. If you want to manage fonts yourself, you can disable this by setting ui.fonts: false in your nuxt.config.ts and handle font loading manually in your CSS.
See: Nuxt UI Fonts Usage What you should do: 1. Move your font file to public/fonts/ (not assets/). 2. Reference it in your CSS with an absolute path:
@font-face {
font-family: 'NerdFontsSymbols Nerd Font';
src: url('/fonts/Symbols-2048-em Nerd Font Complete.woff2') format('woff2');
font-weight: 400;
font-style: normal;
}

@font-face {
font-family: 'NerdFontsSymbols Nerd Font';
src: url('/fonts/Symbols-2048-em Nerd Font Complete.woff2') format('woff2');
font-weight: 400;
font-style: normal;
}

3. If you are using Nuxt UI and do not want automatic font handling, add this to your nuxt.config.ts:
export default defineNuxtConfig({
ui: {
fonts: false
}
})

export default defineNuxtConfig({
ui: {
fonts: false
}
})

Then manage your font loading manually in your CSS. This approach is directly supported and recommended by the Nuxt documentation for reliable font loading in production builds. If you continue to see the error after these changes, double-check the file path and ensure the font file is present in the public/fonts/ directory at build time. If you need to use the assets/ directory for some reason, be aware that Nuxt will process and hash the file, and you must reference it using the correct build-time path, which can be more complex and error-prone. If you follow these steps and still encounter issues, please provide more details about your configuration. Nuxt Styling Documentation
Nuxt UI Fonts Usage ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@662227196814819349> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Adam
AdamOP2w ago
Hold on just saw in nuxt fonts's docs that if it tries to process it, logically, i should add it to my lnuxt config well adding it gives still some issues: On prod, it now works, but not on dev anymore also had to specify the /fonts/ prefix in the configuration of nuxt-fonts well for now removed the assets prefix, I get some warnings but it works both on prod and dev

Did you find this page helpful?