-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v4] Cannot apply unknown utility class: xxx #15778
Comments
You may not want to |
After attempting migration, my app won't start at all, instead I get console full of these errors warning about not being able to apply basic tailwind classes. I'm yet to figure out what goes wrong. |
As an aside, Adam Wathan (creator of Tailwind) does seem to advocate avoiding |
Oh! I think I should have understood. Thank you! |
Same here for me in scss file |
Could you provide an example that reproduces the error please? |
Sure. Something like that webpack.config.js
src/scss/app.scss
postcss.config.js
src/scss/components/_buttons.scss
Build files using
|
You may need to use It could also be that Sass evaluates the Otherwise, please consider providing a more all-encompassing example - like a remotely-hosted git repository. This is so I don't have to figure out which packages I need to install and other such things that take time to setup but not condusive to the problem. |
Several things: 1. Can't resolveI was initially getting:
And this is because Sass processes the files before Tailwind. Thus, the partials that have the Thus we should change the -@reference "../app.scss";
+@reference "./app.scss"; 2. Cannot apply unknown utility classThen, I was getting:
And this was because there was no @import "tailwindcss";
+
+@theme {
+ --color-white-500: foo;
+} |
Awesome, it's working. Thank you so much! |
Hello, I also encounter the same problem when upgrade to tailwind v4. <style scoped>
@tailwind base;
@layer base {
input:focus {
@apply shadow-md
}
input {
@apply bg-transparent border-2 border-gray-300 rounded-lg py-2 px-4 inline-block w-1/2 appearance-none leading-normal
}
button {
@apply bg-transparent ml-10 hover:bg-blue-500 text-blue-700 dark:text-green-400 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded
}
}
</style> To reproduce it, please use the this branch: https://github.com/JingMatrix/jingmatrix.github.io/tree/tailwind The error is:
|
It seems you are missing <style scoped>
+@reference "tailwindcss/theme.css";
@tailwind base;
@layer base { As an aside, Adam Wathan (creator of Tailwind) does seem to advocate avoiding |
Thanks for your response. I didn't understand that |
To be fair, |
Now I have added
Could you please take a look at my css file Here, I am using the font-family utility of tailwindcss. |
It seems like you haven't included the You'd need to use the |
Thank you very much, your conjecture was correct. export default {
darkMode: "class",
content: [
"./components/**/*.{html,js,vue,ts,md}",
"./content/**/*.{html,js,vue,ts,md}",
"./content/.vitepress/**/*.{html,js,vue,ts,md}",
],
plugins: [typography],
}; |
|
I still found buggy behavior related to this @reference workwround. |
Yep, so it's because Vitepress's styles are not in any cascade layers while you have your styles in cascade layers. Styles in cascade layers have lower precedence than styles outside them, hence they are overridden. |
I don't think your explanation is correct, because using the devtools your will find that both rules are loaded by the same bundle css file. |
I see, I misunderstood your word Hence, this is indeed also a breaking change. |
I'm not competent enough to evaluate the design decision, and not about to start arguing what's the "right" way to apply Tailwind. However...having to not manually reference CSS files everywhere was one of the reasons I started using it. Going through the whole codebase adding |
Hey folks! We've just added a section on our upgrade guides that goes into more detail about the changed behavior for To give further technical background, imagine a setup with two different Tailwind CSS configurations like this: /* src/admin/index.css */
@theme {
--color-primary: #fff;
} /* src/app/index.css */
@theme {
--color-primary: #000;
} Since CSS modules, or Let us know if you run into any other issues with this, thanks! |
Is there any way to pass the absolute path? Relative paths are very problematic since moving files with import autoupdate is a big deal in IDEs. |
You can try starting the path with a slash: @reference "/home/users/project/src/app.css"; |
uh... Absolute path in the project, not in the system. |
You could try using Subpath Imports like: "imports": {
"#app.css": "./path/to/app.css"
}, @reference "#app.css"; |
So I am a bit confused. In tailwind v3 I was able to create global style classes using tailwind syntax like
i checked out the docs and only find the alternative using @Utility but using general CSS syntax. Is there another possibility to still have global classes but with tailwind syntax? |
i'm very confused. i can't get @apply to work basically at all now. |
You probably need to use the |
In the stylesheet where you are using |
how?? |
See the documentation for details. |
Hello, I have previously upgraded the You can refer to this repo nextjs-nextra-starter and Commits |
很酷 |
|
Whats the reason for this change? Performance? |
See #15778 (comment) |
Thanks. Assuming using Angular and having 100 components, do I have to add @reference to every component or is there an easier solution? |
You'd need to add |
We have in our Angular 19 project about 100+ .scss files that are depending on If at least there was a option to use Or having the option to having @apply etc global through opt-in would also be a option. Forgoing on using I hope somehow there will be / is a better solution. |
You trying using Subpath imports to create an alias to your main stylesheet like: // package.json
{
// …
"imports": {
"#my-theme.css": "./path/to/my/theme.css"
}
} @reference "#my-theme.css"; |
That does not seem to work for stylesheets. I have aslo tried:
That works fine for @import / @use but does not with @reference. |
For now i will use the file watcher from webstorm to add the @reference when needed /**
* @file WebStorm File Watcher Configuration for `add-tailwind-reference.js`
*
* This JSDoc comment provides instructions for setting up a WebStorm File Watcher
* to automatically manage `@reference` lines in SCSS files based on the presence of `@apply`.
*
* @example
* // 1. Open WebStorm Settings:
* // File > Settings... (or WebStorm > Preferences... on macOS)
* // Navigate to Tools > File Watchers.
*
* // 2. Add a New File Watcher:
* // Click the + (Add) button.
* // Select Custom.
*
* // 3. Configure the File Watcher:
* // Name: add-tailwind-reference (or any descriptive name).
* // Files to Watch:
* // File type: SCSS style sheet.
* // Scope: Project Files.
* // Track only root files: (Leave unchecked unless needed).
* // Tool to Run on Changes:
* // Program: C:\Program Files\nodejs\node (Adjust if your Node.js path is different).
* // Arguments: add-tailwind-reference.js $FilePath$
* // - `add-tailwind-reference.js`: The name of your script.
* // - `$FilePath$`: WebStorm macro for the changed file's path.
* // Output paths to refresh: (Leave blank or add specific paths).
* // Working directory: $ContentRoot$.
* // Environment variables: (Leave as is).
* // Advanced Options:
* // Auto-save edited files to trigger the watcher: (Check for immediate execution on save).
* // Trigger the watcher on external changes: (Check to trigger on external modifications).
* // Trigger the watcher regardless of syntax errors: (Check with caution).
* // Create output file from stdout: (Leave unchecked).
* // Show console: On error.
* // Output filters: (Leave blank or add regex filters).
*
* // 4. Click OK to save the configuration.
*
* @remarks
* - Ensure the Node.js path is correct.
* - Place `add-tailwind-reference.js` in the project root or a discoverable location.
* - Verify file permissions for Node.js.
* - Use `console.log()` in the script for debugging.
*
* @see {@link https://www.jetbrains.com/help/webstorm/file-watchers.html WebStorm File Watchers Documentation}
* @see {@link https://nodejs.org/ Node.js Official Website}
*
* @param {string} $FilePath$ - The absolute path of the SCSS file that triggered the watcher. (WebStorm macro)
* @param {string} $ContentRoot$ - The root directory of the project. (WebStorm macro)
*
* @example
* // Example command line arguments:
* // add-tailwind-reference.js /path/to/your/file.scss
*
* @example
* // Example script usage:
* // node add-tailwind-reference.js path/to/your/file.scss
*/
const fs = require('fs');
const path = require('path');
function processScssFile(filePath, cssFilePath) {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading file ${filePath}: ${err}`);
return;
}
const relativePath = path.relative(path.dirname(filePath), cssFilePath).replace(/\\/g, '/');
const referenceLine = `@reference "${relativePath}";\n`;
const applyRegex = /@apply\b/;
if (applyRegex.test(data)) {
// Check for the reference line *before* adding it
if (!data.includes(referenceLine.trim())) { // Use includes for a more robust check.
const updatedData = referenceLine + data;
fs.writeFile(filePath, updatedData, 'utf8', (writeErr) => {
if (writeErr) {
console.error(`Error writing to file ${filePath}: ${writeErr}`);
} else {
console.log(`Updated ${filePath} with reference: ${referenceLine.trim()}`);
}
});
} else {
console.log(`${filePath} already contains the reference.`);
}
} else {
// Remove reference if @apply is not found
const trimmedData = data.replace(/^[\s\n]+/, ''); // Remove leading whitespace and newlines
if (trimmedData.startsWith(referenceLine.trim())) {
const updatedData = data.slice(referenceLine.length);
fs.writeFile(filePath, updatedData, 'utf8', (writeErr) => {
if (writeErr) {
console.error(`Error writing to file ${filePath}: ${writeErr}`);
} else {
console.log(`Removed reference from ${filePath}.`);
}
});
} else {
console.log(`${filePath} does not contain the reference.`);
}
}
});
}
processScssFile(process.argv[2], 'path-to-your-theme/theme.css'); |
I just create a new global.css which is based on Tailwind CSS v4. Obviously after reading the docs. It guided me thoroughly because font-extrabold, shadow-100 do not work in it anymore. global.css
|
Yo tengo el siguiente error en el global.css: Error: Cannot apply unknown utility class: border-border ./app/globals.css.webpack[javascript/auto]!=!./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[13].oneOf[10].use[2]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[13].oneOf[10].use[3]!./app/globals.css Codigo: @layer base { |
Can anyone guide me whats wrong with my code why and it is not forwarding the attributes @import "tailwindcss"; body { @layer base {
} @theme {
} @layer utilities {
} .nav-hover-btn { .nav-hover-btn::after { .nav-hover-btn:hover::after { .floating-nav { .absolute-center { .flex-center { .mask-clip-path { .special-font b { .hero-heading { .about-subtext { .about-image { .animated-title { .animated-word { .bento-tilt_1 { .bento-tilt_2 { .bento-title { .story-img-container { .story-img-mask { .story-img-content { .gallery-img-container { .gallery-img { .gallery-img-4 { .sword-man-clip-path { .contact-clip-path-1 { .contact-clip-path-2 { /* Indicator Animation */ .indicator-line.active { @Keyframes indicator-line { /* Three-Body Loader (From Uiverse.io) */ .three-body__dot { .three-body__dot:after { .three-body__dot:nth-child(1) { .three-body__dot:nth-child(1)::after { .three-body__dot:nth-child(2) { .three-body__dot:nth-child(2)::after { .three-body__dot:nth-child(3) { .three-body__dot:nth-child(3)::after { @Keyframes spin78236 { @Keyframes wobble1 { @Keyframes wobble2 { |
就像这个评论所说 #15778 (comment) 你需要在你使用 |
Hello!
After upgrading from v3 to v4(via CLI), I encountered some error:
Cannot apply unknown utility class: text-card-foreground
.This never happened in v3.
After some trial and error, I found that it seems necessary to import the main CSS file in my CSS.
Is this the expected behavior? This will cause a large number of component styles to have issues.
Or, is there a trick for automatic import?
The text was updated successfully, but these errors were encountered: