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/postcss fails to resolve font URLs in external packages with Vite #16636
The CSS entrypoint imports @fortawesome/fontawesome-free package CSS. When you run npm run build, you'll see errors indicating that font URLs within that CSS have failed to resolve:
../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-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-v4compatibility.woff2 referenced in ../webfonts/fa-v4compatibility.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-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-v4compatibility.ttf referenced in ../webfonts/fa-v4compatibility.ttf didn't resolve at build time, it will remain unchanged to be resolved at runtime
This exact same setup works without issues on Tailwind v3, so it seems like a regression in v4.
changed the title [-]tailwindcss/@postcss fails to resolve font URLs in external packages with Vite[/-][+]@tailwindcss/postcss fails to resolve font URLs in external packages with Vite[/+]on Feb 18, 2025
If I switch from @tailwindcss/postcss to @tailwindcss/vite, everything seems to import correctly as well, so it seems like an issue in @tailwindcss/postcss.
Personally I would love to switch to @tailwindcss/vite in our project, but unfortunately we still have quite a lot of Sass code, which the Vite plugin doesn't support.
If I switch from @tailwindcss/postcss to @tailwindcss/vite, everything seems to import correctly as well, so it seems like an issue in @tailwindcss/postcss.
Personally I would love to switch to @tailwindcss/vite in our project, but unfortunately we still have quite a lot of Sass code, which the Vite plugin doesn't support.
i also had issue with vite plugin. upgrading laravel application with vite, if i use vite plugin i have several compilation error, with postcss plugin works well
@janko Huh, do you have a setup how this works without the Tailwind PostCSS plugin?
I think that the import to @fortawesome/fontawesome-free/css/all.css might not have been resolved by PostCSS at all (so your bundler would have inlined it but there is no bundler in this repro) or you may have used other PostCSS plugins. In Vite we manually rewrite url imports like this to be relative to the right path but we never did this on the PostCSS side.
What you can try is to change using an @import url(…) instead, this effectively will leave it as-is and @tailwindcss/postcss won't attempt to inline it:
(Note that it will need to be reordered though since the latter import will expand into CSS)
@DonCamillo11@neapolis79 Do you mind attaching a repro and creating a new issue report? If you're using the Vite plugin this should work since we do url rebasing there.
@philipp-spiess I just pushed vite-plugin, v3 and url branches to the repo, which switch to using @tailwindcss/vite, Tailwind v3, and @import url(...) respectively. Font Awesome gets successfully imported with @tailwindcss/vite and Tailwind v3 (without additional changes to the import), and I added an icon to the <body> just to prove that it works. I tried switching to @import url(...) with changed order, but the errors are the same unfortunately, and the icon doesn't get rendered.
I think that the import to @fortawesome/fontawesome-free/css/all.css might not have been resolved by PostCSS at all (so your bundler would have inlined it but there is no bundler in this repro) or you may have used other PostCSS plugins.
I might be misunderstanding, but isn't Vite my bundler here? There is no Vite config in any of the branches other than the @tailwindcss/vite one, but I was using Vite commands defined in package.json (e.g. npm run build), as Vite config seems to be optional.
The Vite build output shows whether fonts were resolved, and I also tested rendering the icon to verify it. This is the successful build:
Thanks for the repro. Will need to look more into it and have to understand what Vite does behind the scenes here so that it works with no Tailwind CSS plugin present 🤔
@DonCamillo11@neapolis79 Do you mind attaching a repro and creating a new issue report? If you're using the Vite plugin this should work since we do url rebasing there.
Apologies if this is off topic or caused by a different issue, but this workaround also fixed my problem.
My issue: Vite hot reload fails to pick up changes in SASS files imported into top-level SASS file.
My build is Vite + tailwindcss/postcss. Vite css uses modern-compiler api option.
main.js: import '@/assets/style.scss'
style.scss:
@use "tailwindcss";
@use "main.scss";
If I change a style in main.scss, Vite pushes a hot-reload of style.scss (which inlines main.scss), but it doesn't include the changes. If I npm run dev from scratch the changes are included.
Things which worked: Using url for import: @import url("@/assets/main.scss");
Having the same issue with Webpack and postcss-loader. When the @tailwindcss/postcss plugin is included, imported CSS files from node_modules get inlined without bringing their assets with them.
Activity
[-]tailwindcss/@postcss fails to resolve font URLs in external packages with Vite[/-][+]@tailwindcss/postcss fails to resolve font URLs in external packages with Vite[/+]janko commentedon Feb 18, 2025
If I switch from
@tailwindcss/postcssto@tailwindcss/vite, everything seems to import correctly as well, so it seems like an issue in@tailwindcss/postcss.Personally I would love to switch to
@tailwindcss/vitein our project, but unfortunately we still have quite a lot of Sass code, which the Vite plugin doesn't support.DonCamillo11 commentedon Feb 19, 2025
Same issue here using vite.
neapolis79 commentedon Feb 20, 2025
i also had issue with vite plugin. upgrading laravel application with vite, if i use vite plugin i have several compilation error, with postcss plugin works well
philipp-spiess commentedon Feb 20, 2025
@janko Huh, do you have a setup how this works without the Tailwind PostCSS plugin?
I think that the import to
@fortawesome/fontawesome-free/css/all.cssmight not have been resolved by PostCSS at all (so your bundler would have inlined it but there is no bundler in this repro) or you may have used other PostCSS plugins. In Vite we manually rewrite url imports like this to be relative to the right path but we never did this on the PostCSS side.What you can try is to change using an
@import url(…)instead, this effectively will leave it as-is and@tailwindcss/postcsswon't attempt to inline it:(Note that it will need to be reordered though since the latter import will expand into CSS)
@DonCamillo11 @neapolis79 Do you mind attaching a repro and creating a new issue report? If you're using the Vite plugin this should work since we do url rebasing there.
janko commentedon Feb 20, 2025
@philipp-spiess I just pushed
vite-plugin,v3andurlbranches to the repo, which switch to using@tailwindcss/vite, Tailwind v3, and@import url(...)respectively. Font Awesome gets successfully imported with@tailwindcss/viteand Tailwind v3 (without additional changes to the import), and I added an icon to the<body>just to prove that it works. I tried switching to@import url(...)with changed order, but the errors are the same unfortunately, and the icon doesn't get rendered.I might be misunderstanding, but isn't Vite my bundler here? There is no Vite config in any of the branches other than the
@tailwindcss/viteone, but I was using Vite commands defined inpackage.json(e.g.npm run build), as Vite config seems to be optional.The Vite build output shows whether fonts were resolved, and I also tested rendering the icon to verify it. This is the successful build:
and this is the unsuccessful build (font files are absent):
philipp-spiess commentedon Feb 20, 2025
@janko Ah sorry I oversaw Vite here, sorry! 🤦
Thanks for the repro. Will need to look more into it and have to understand what Vite does behind the scenes here so that it works with no Tailwind CSS plugin present 🤔
DonCamillo11 commentedon Feb 20, 2025
@philipp-spiess please see this issue here
#16700
walnutjon commentedon Feb 21, 2025
Apologies if this is off topic or caused by a different issue, but this workaround also fixed my problem.
My issue: Vite hot reload fails to pick up changes in SASS files imported into top-level SASS file.
My build is Vite + tailwindcss/postcss. Vite css uses modern-compiler api option.
main.js:
import '@/assets/style.scss'style.scss:
If I change a style in main.scss, Vite pushes a hot-reload of style.scss (which inlines main.scss), but it doesn't include the changes. If I npm run dev from scratch the changes are included.
Things which worked: Using url for import:
@import url("@/assets/main.scss");Things I've tried:
mirite commentedon Feb 25, 2025
Having the same issue with Webpack and postcss-loader. When the @tailwindcss/postcss plugin is included, imported CSS files from node_modules get inlined without bringing their assets with them.
philipp-spiess commentedon Mar 7, 2025
Hey folks! Sorry for the long wait but a fix for this is coming with the next patch release.
janko commentedon Mar 7, 2025
Appreciate the fix, thanks! 🙏🏻
Enable URL rewriting for PostCSS (tailwindlabs#16965)
DonCamillo11 commentedon Mar 11, 2025
@philipp-spiess Thanks, but I still have the same problem.
philipp-spiess commentedon Mar 11, 2025
@DonCamillo11 Mind creating a new GitHub issue with a reproduction for that? Thanks!
DonCamillo11 commentedon Mar 12, 2025
@philipp-spiess Can you please reopen this issue #16700. I just updated the repo, thanks.
Rewrite `url(…)`s of stylesheets inlined before `@tailwindcss/postcss…