You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@tailwindcss fails to resolve font URLs in external packages with Vite #16700
I try to import fontawesome pro in my app.css. When running npm run build I get the following errors:
../webfonts/fa-brands-400.woff2 referenced in ../webfonts/fa-brands-400.woff2 didn't resolve at build time, it will remain unchanged to be resolved at runtime
../webfonts/fa-duotone-900.woff2 referenced in ../webfonts/fa-duotone-900.woff2 didn't resolve at build time, it will remain unchanged to be resolved at runtime
../webfonts/fa-regular-400.woff2 referenced in ../webfonts/fa-regular-400.woff2 didn't resolve at build time, it will remain unchanged to be resolved at runtime
../webfonts/fa-solid-900.woff2 referenced in ../webfonts/fa-solid-900.woff2 didn't resolve at build time, it will remain unchanged to be resolved at runtime
../webfonts/fa-light-300.woff2 referenced in ../webfonts/fa-light-300.woff2 didn't resolve at build time, it will remain unchanged to be resolved at runtime
../webfonts/fa-brands-400.ttf referenced in ../webfonts/fa-brands-400.ttf didn't resolve at build time, it will remain unchanged to be resolved at runtime
../webfonts/fa-duotone-900.ttf referenced in ../webfonts/fa-duotone-900.ttf didn't resolve at build time, it will remain unchanged to be resolved at runtime
../webfonts/fa-regular-400.ttf referenced in ../webfonts/fa-regular-400.ttf didn't resolve at build time, it will remain unchanged to be resolved at runtime
../webfonts/fa-solid-900.ttf referenced in ../webfonts/fa-solid-900.ttf didn't resolve at build time, it will remain unchanged to be resolved at runtime
../webfonts/fa-light-300.ttf referenced in ../webfonts/fa-light-300.ttf didn't resolve at build time, it will remain unchanged to be resolved at runtime
It was working with Tailwind v3
but after updating my Laravel application to Tailwind 4 there seem to be a problem building the files.
@DonCamillo11 Thanks for setting this up, the repro is really good and helpful! You were right though that is the same issue when you said you're using "Vite" I thought this happens for you using the Vite integration but you are indeed also using the PostCSS extension. Going to merge this back into the other issue I just sent you from 😬 Sorry!
@philipp-spiess I have an issue that feels directly related to this one, but I was hoping to run it by you to get a sense of whether I should open another issue, provide my own reproduction here, etc. My situation is as follows:
I set up my project initially with the Tailwind CLI.
I needed to use postcss-nesting due to client requirements.
I switched to PostCSS via @tailwindcss/postcss.
All relative font URLs are rewritten to absolute URLs relative to the input CSS file.
My file structure has src and public folders, and the @font-face entries in ./src/fonts.css look something like this:
The actual font files are in ./public/fonts/. This worked fine with the Tailwind CLI, but with @tailwindcss/postcss, this gets updated in ./public/style.css to:
Thank you for providing a detailed report and a reproduction repository.
Confirmed with Font Awesome Free
I replaced @fortawesome/fontawesome-pro with @fortawesome/fontawesome-free (version 6.5.1), and correctly updated the app.css import paths.
Fonts like fa-brands-400.woff2 and other font files are not being resolved correctly.
The build logs indicate that url(...) references are being left as-is and resolved at runtime.
I updated the app.css import paths in vite.config.js. However, I still encountered the same issue during the build:
Additionally, I encountered the following errors due to the absence of Pro-only files like duotone.css and light.css in the free version. After removing those imports, the build proceeds but still doesn't resolve the font URLs.
Here's a summary of what I tested:
Font Awesome Free (6.5.1) for CSS files: fontawesome, brands, regular, solid.
Tailwind CSS (v3.4.1).
Vite (v6.2.6) for production build.
This suggests that the issue isn’t tied to the Pro version, and it may be a bug with how Vite or Tailwind CSS handles relative url() references in external CSS files.
It should be possible to dynamically populate prefixesToStrip based on the directory structure of your source CSS files.
I was going to write up a proposal for allowing shouldRewriteUrls to be set to false via a plugin option; want me to tag you when I add that discussion?
@inkstak Good call on the absolute paths! I'm trying to keep the existing paths the same pending a resolution to the issue, despite relative paths leading to more convoluted replacements. If this becomes the permanent state of things, I think I'll migrate to absolute paths at that point.
Thank you! I am using Vite and was able to move the import to the main js file which works in the build without having to change anything postcss wise as it bypasses the CSS layer. Thank you for following up though, hopefully useful for anyone else coming across this
Activity
wongjn commentedon Feb 21, 2025
Git patch to get the reproduction to run properly:
philipp-spiess commentedon Feb 21, 2025
@DonCamillo11 Thanks for setting this up, the repro is really good and helpful! You were right though that is the same issue when you said you're using "Vite" I thought this happens for you using the Vite integration but you are indeed also using the PostCSS extension. Going to merge this back into the other issue I just sent you from 😬 Sorry!
DonCamillo11 commentedon Feb 21, 2025
@philipp-spiess sorry, my fault 🙇
philipp-spiess commentedon Feb 21, 2025
@DonCamillo11 Nah that's on me, thank you for providing the repro!
gregsullivan commentedon Mar 13, 2025
@philipp-spiess I have an issue that feels directly related to this one, but I was hoping to run it by you to get a sense of whether I should open another issue, provide my own reproduction here, etc. My situation is as follows:
postcss-nestingdue to client requirements.@tailwindcss/postcss.My file structure has
srcandpublicfolders, and the@font-faceentries in./src/fonts.csslook something like this:(
fonts.cssis imported into./tailwind.css.)The actual font files are in
./public/fonts/. This worked fine with the Tailwind CLI, but with@tailwindcss/postcss, this gets updated in./public/style.cssto:I saw in #16636 you said this:
From that it sounds like these
url()values shouldn't be rewritten, but I was hoping you could lend some clarity as far as that goes.Thanks for all your work on this—much appreciated!
gregsullivan commentedon Mar 14, 2025
Sorry, @philipp-spiess — after rereading everything today, I now understand that this behaviour is intentional, via #16965.
Would you be open to a pull request allowing
shouldRewriteUrlsto be set tofalsevia a plugin option?Bhavdeep-Sai commentedon Apr 13, 2025
Hi @DonCamillo11,
Thank you for providing a detailed report and a reproduction repository.
Confirmed with Font Awesome Free
I replaced
@fortawesome/fontawesome-prowith@fortawesome/fontawesome-free(version 6.5.1), and correctly updated the app.css import paths.fa-brands-400.woff2and other font files are not being resolved correctly.url(...)references are being left as-is and resolved at runtime.I updated the app.css import paths in
vite.config.js. However, I still encountered the same issue during the build:Additionally, I encountered the following errors due to the absence of Pro-only files like
duotone.cssandlight.cssin the free version. After removing those imports, the build proceeds but still doesn't resolve the font URLs.Here's a summary of what I tested:
fontawesome,brands,regular,solid.This suggests that the issue isn’t tied to the Pro version, and it may be a bug with how Vite or Tailwind CSS handles relative
url()references in external CSS files.inkstak commentedon May 5, 2025
@gregsullivan Same situation, we used to rely on Rails to serve static assets such as fonts & images.
All our
url()are now wrong.Did you find a workaround ?
gregsullivan commentedon May 5, 2025
@inkstak This is far from an ideal solution, but I've been using
postcss-urlto strip the paths now added by@tailwindcss/postcss:It should be possible to dynamically populate
prefixesToStripbased on the directory structure of your source CSS files.I was going to write up a proposal for allowing shouldRewriteUrls to be set to false via a plugin option; want me to tag you when I add that discussion?
gregsullivan commentedon May 5, 2025
You could also probably use
patch-package. You'd need to change this:to this:
shouldRewriteUrls:0in
@tailwindcss/postcss/dist/index.js. This is also far from ideal, but possibly viable as a temporary fix.inkstak commentedon May 6, 2025
@gregsullivan Thanks a lot !
postcss-urlwas a good start.I've also updated all
url()with absolute paths because it seems Tailwind doesn't rewrite absolute paths.@font-face { font-family: "Foo"; - src: url("foo.woff2") format("woff2"), + src: url("/assets/fonts/foo.woff2") format("woff2"), font-weight: 400; font-style: normal; }Then it's easier to use
postcss-urlto replace all of them with appropriate paths:I'll appreciate.
gregsullivan commentedon May 6, 2025
@inkstak Good call on the absolute paths! I'm trying to keep the existing paths the same pending a resolution to the issue, despite relative paths leading to more convoluted replacements. If this becomes the permanent state of things, I think I'll migrate to absolute paths at that point.
I'll tag you on the discussion when I post it!
DonCamillo11 commentedon Jun 20, 2025
@philipp-spiess Is there something new on this topic?
gregsullivan commentedon Jul 4, 2025
@inkstak I asked about this on Discord. Good news:
#18321
thecrypticace commentedon Jul 30, 2025
The PostCSS plugin will have an API for this in the next release 👍
Allow users to disable url rewriting in the PostCSS plugin (#18321)
jamesmacwhite commentedon Mar 26, 2026
I've just come across this problem in on a Tailwind v3 to v4 upgrade with Font Awesome 6 Pro.
I'm sorry for bumping an old issue but what is the actual solution, is it disabling URL rewriting?
gregsullivan commentedon Mar 26, 2026
If you're using PostCSS, this should work in your
postcss.config.jsfile:jamesmacwhite commentedon Mar 26, 2026
Thank you! I am using Vite and was able to move the import to the main js file which works in the build without having to change anything postcss wise as it bypasses the CSS layer. Thank you for following up though, hopefully useful for anyone else coming across this
Rewrite `url(…)`s of stylesheets inlined before `@tailwindcss/postcss…