Closed
Description
What version of Tailwind CSS are you using?
3.4.3
What build tool (or framework if it abstracts the build tool) are you using?
Vite
What version of Node.js are you using?
v21.7.3
What browser are you using?
Chrome
What operating system are you using?
macOS
Reproduction URL
Describe your issue
There's a PostCSS warning in the console:
A PostCSS plugin did not pass the `from` option to `postcss.parse`. This may cause imported assets to be incorrectly transformed. If you've recently added a PostCSS plugin that raised this warning, please contact the package author to fix the issue.
It starts when you define your own CSS utility and use it with the before: or after:.
Example:
css file:
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer utilities {
.bg-own {
background-color: red;
}
}Usage:
<div class="before:bg-own" />Reacted by Slava Nossar and Marco Ilari
Metadata
Metadata
Assignees
Labels
No labels
Activity
wongjn commentedon Apr 30, 2024
This could be related to the
beforevariant core plugin (this would happen withaftertoo), it adds a newDeclarationwithout asourceproperty:tailwindcss/src/corePlugins.js
Line 64 in f1f419a
The
vite-url-rewritePostCSS plugin internally in Vite relies on thissourceproperty:As per the 2.4 of the PostCSS Plugin Guidelines:
So perhaps we could clone a declaration inside the variant plugin, instead of creating a new one from scratch? But why only with your own declared utilities? The plot thickens!
It seems when we are generating the CSS:
tailwindcss/src/lib/expandTailwindAtRules.js
Lines 244 to 246 in f1f419a
We skip setting
sourcerecursively ifpreserveSourceistrue:tailwindcss/src/util/cloneNodes.js
Lines 22 to 25 in f1f419a
And for
@layer-defined class rules, thispreserveSourceis indeed set totrue:tailwindcss/src/lib/setupContextUtils.js
Lines 724 to 726 in f1f419a
Thus, for plugin-defined utilities, we don't have to worry about retaining
sourcein thebefore/afterplugin but we should do for@layer-defined class rules if seems.So what would be the best way to solve this? Push the onus on to the plugins that use the PostCSS API to ensure they create appropriate
sourcevalues? This would mean we could fix the core plugins to match this. Or try to fill in gaps incloneNodes()? If we do want to fill in the gaps ourselves, should thesourcepoint to the original source of the@layerrule or the relevant@tailwinddeclaration?Example test for this:
eugster commentedon May 22, 2024
Found this, because I just got the same error when using a custom utility with
before.As I got the error after moving the utility-class from an apply to markup I found some additional information:
If used with
@applycustom utility combined withbefore:doesn't throw the error mentioned.I verified this in the in the Reproduction-Url of gynekolog
EDIT: using
@applycustom utility combined withbefore:doesn't throw an error in develop, but it breaks the build process. At least in one component. In the other the build throws just the same error as with develop, but runs.justb3a commentedon Jul 3, 2024
Got the same error message, removed all
before|afterand@applydirectives and still got the error message.Turns out the following lines introduced the message:
I think, rewriting a reserved name is not allowed. I have no idea why
bg-nonedoesn't work on my side.eric-d-johnson commentedon Jul 15, 2024
I'm experiencing this same error message too. I have tracked it down to using
.text-blackin my tailwind.css fileMoving it out side of the
@utilitieslayer works for me.onehorsetown commentedon Oct 25, 2024
I too tracked down a single item that caused the "A PostCSS plugin did not pass the
fromoption topostcss.parse. This may cause imported assets to be incorrect…" warning during vite transformation:As above, taking it out of the
@layer utilitiessection caused the warning to go away.mrleblanc101 commentedon Jan 20, 2025
Same issue.
I have these utilities:
And I use
class="before:flag-left after:flag-right ..."to apply the clip-path to my pseudo-element.If I comment out my
flag-leftandflag-rightcustom utilities, the error goes away.thecrypticace commentedon May 8, 2025
The next release will have support for source maps in development — which should get rid of this warning/error.
Add support for source maps (tailwindlabs#17775)