question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with invalid classname in custom CSS using @apply when watching

See original GitHub issue

What version of Tailwind CSS are you using?

Tailwind 3.2.3

What version of Node.js are you using?

For example: v19.0.1

What browser are you using?

n/a

What operating system are you using?

macOS 12.6

Steps to reproduce

Download the small example test project:

tailwind-crash.zip

Follow the instructions in the README.md

Describe your issue

I use a pretty basic setup with CLI scripts in package.json like this:

{
  "name": "postcss8-tailwind",
  "repository": "",
  "private": true,
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev": "tailwindcss -i ./css/site.css -o ./build/css/site.css --postcss --minify --watch",
    "prod": "NODE_ENV=production tailwindcss -i ./css/site.css -o ./build/css/site.css --postcss --minify"
  },
  "dependencies": {
    "@tailwindcss/forms": "^0.5.3",
    "@tailwindcss/typography": "^0.5.8",
    "alpinejs": "^3.10.5",
    "postcss-import": "^15.0.0",
    "tailwindcss-debug-screens": "^2.2.1"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.13",
    "postcss": "^8.4.18",
    "tailwindcss": "^3.2.3"
  }
}

Since the JIT, i mainly just use dev script to compile my CSS while watching. The normal and expected behavior when accidentally typing an invalid classname, was the the compiler would see the change, attempt to recompile and spit out an error indicating the line number and invalid class in question. For a few weeks i’ve noticed that I would not get this neat output, rather it would stack-trace, and I would have to scroll up in the terminal to find the first line that indicated the file, line number and the class in question that was in valid.

For the past couple of days I’ve noticed that rather than this stack trace, the compile just gets stuck after the Rebuilding... text is output. No errors, no messages. Fixing the bad class, causes the file to recompile again with the Done in XXms message. I now have to notice it got stuck manually exit out of the watch, then manually run the command again from CLI to get the stacktrace that I can then scroll back to find the bad classname.

I’ve updated everything i can think of, including moving from Node 18 to latest Node 19.0.1. I get this error over multiple projects, so it’s not just this one instance. Is there any known issues with the latest version of PostCSS or is this coming from tailwindcss specifically?

Example of the partial StackTrace when running:

➜ npm run dev

> postcss8-tailwind@1.0.0 dev
> tailwindcss -i ./css/site.css -o ./build/css/site.css --postcss --minify --watch


Rebuilding...
/Users/joe/Projects/www/my-site/theme/custom/node_modules/postcss/lib/input.js:148
      result = new CssSyntaxError(
               ^

CssSyntaxError: tailwindcss: /Users/joe/Projects/www/my-site/theme/custom/css/custom/typography.css:5:5: The `right-0x` class does not exist. If `right-0x` is a custom class, make sure it is defined within a `@layer` directive.
    at Input.error (/Users/joe/Projects/www/my-site/theme/custom/node_modules/postcss/lib/input.js:148:16)
    at AtRule.error (/Users/joe/Projects/www/my-site/theme/custom/node_modules/postcss/lib/node.js:60:32)
    at processApply (/Users/joe/Projects/www/my-site/theme/custom/node_modules/tailwindcss/lib/lib/expandApplyAtRules.js:376:29)
    at /Users/joe/Projects/www/my-site/theme/custom/node_modules/tailwindcss/lib/lib/expandApplyAtRules.js:524:9
    at /Users/joe/Projects/www/my-site/theme/custom/node_modules/tailwindcss/lib/processTailwindFeatures.js:55:50
    at Object.Once (/Users/joe/Projects/www/my-site/theme/custom/node_modules/tailwindcss/lib/cli/build/plugin.js:251:19)
    at LazyResult.runOnRoot (/Users/joe/Projects/www/my-site/theme/custom/node_modules/postcss/lib/lazy-result.js:337:23)
    at LazyResult.runAsync (/Users/joe/Projects/www/my-site/theme/custom/node_modules/postcss/lib/lazy-result.js:393:26)
    at async Object.watch (/Users/joe/Projects/www/my-site/theme/custom/node_modules/tailwindcss/lib/cli/build/plugin.js:348:13)
    at async build (/Users/joe/Projects/www/my-site/theme/custom/node_modules/tailwindcss/lib/cli/build/index.js:40:9) {
  reason: 'The `right-0x` class does not exist. If `right-0x` is a custom class, make sure it is defined within a `@layer` directive.',
  file: '/Users/joe/Projects/www/my-site/theme/custom/css/custom/typography.css',
  source: '[x-cloak] { display: none; }\n' +
    '\n' +
    'body {\n' +
    '  &.debug-screens:before {\n' +
    '    @apply left-inherit right-0x;\n' +
    '  }\n' +
    '\n' +
    '  @apply text-gray-600 tracking-[0.6px] ;\n' +
    '}\n' +
    '\n' +
    '.site-logo {\n' +
    '  img, svg {\n' +
    '    @apply h-full;\n' +

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
thecrypticacecommented, Nov 11, 2022

Hey, thanks for reporting this. I’ve added explicit logging to make sure we’re not relying on any automatic logging from promise rejections (which seemingly doesn’t always work).

This will be in our insiders build that should be published in a few minutes: npm install tailwindcss@insiders

0reactions
rhukstercommented, Nov 11, 2022

Thanks for addressing this so promptly, it’s much appreciated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

invalid - CSS: Cascading Style Sheets - MDN Web Docs
The :invalid CSS pseudo-class represents any , , or other element whose contents fail to validate.
Read more >
How I apply two classname at the same time using css module?
Show activity on this post. <div className={`${style.form_control} ${!inputState.isValid && style.form_control__invalid}`}> </div>.
Read more >
className prop not working with custom DOM elements in ...
The className prop does not appear to get mapped correctly when applied to custom DOM elements in 0.14.0-rc1.
Read more >
Solving the React Error: Not Picking Up CSS Style | Pluralsight
In this guide, you will learn about the errors that can occur while importing a CSS file into your React file.
Read more >
Styles - React Select
The recommended way to provide custom styles to react-select is to use the styles prop. styles takes an object with keys to represent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found