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.

`dark` modifier in HTML can cause circular dependency issue

See original GitHub issue

What version of Tailwind CSS are you using?

v.3.0.23

What build tool (or framework if it abstracts the build tool) are you using?

postcss-cli 8.4.7

What version of Node.js are you using?

v14.18.0

What browser are you using?

Chrome (Version 99.0.4844.83 (Official Build) (x86_64))

What operating system are you using?

macOS Big Sur (11.6.5)

Reproduction URL

Tailwind Play

Describe your issue

Current behavior

This issue applies to projects using the class darkMode strategy.

When using the dark modifier on an custom utility on a HTML element, and that custom utility also contains a dark modifier, you get the following error message:

<css input>: You cannot `@apply` the `dark:bg-green-700` utility here because it creates a circular dependency.

Example:

Custom utility:

.a {
    dark:text-sm
}

HTML

<div class="dark:a">Error</div>

This only applies to the dark modifier.

Expected behavior

  1. This shouldn’t produce an error - it should behave like other modifiers and avoid creating a circular dependency
  2. The error message should point at the usage of the custom utility rather that the implementation of the utility itself. Most likely the problem isn’t with the utility but with the usage.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
dfallmancommented, May 30, 2022

I’ve seen this too lately. I’m pretty sure it was the same problem, i.e. where I had this defined:

.text-subtle {
   @apply text-gray-400 dark:text-gray-600;
}

…that was used like this: <div class="dark:text-subtle"... by someone somewhere in the code base.

From the error message though it sounded like this was a mistake in the config file or in main.css, but where in fact the problem was in code base.

It took me a while to figure out what was going on. So I concur with the last reply, that there seems to be two separate issues here. The first is if this really is a circular dependency? But to me, the more pressing issue is to change the error message to a warning that points the user in the right direction, i.e. that the problem is how a custom class is used in thre code where it creates a circular dependency. Right now the error message doesn’t make any sense.

0reactions
gabrielboekercommented, Sep 14, 2022

Hey @dfallman thanks for your reply. since i was already using that strategy before, it was fairly odd to me that it did not work until i found the issue.

the problem indeed occurs when you (in my case accidentally) assign the dark modifier on a custom class. Somewhere in my code i had a dark:text-primary 😅

I can imagine that more people will do this mistake so I consider that as the solution. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Circular dependency detected" warning - Angular
let say you have 2 modules you are using module A code in module B and also using module B code in module...
Read more >
java - Resolving circular dependency between two classes
What architectural changes could I make to resolve this? UML Diagram interface WebsocketHandler { void onConnect(Session session); void ...
Read more >
Circular dependency - svelte:component : r/sveltejs - Reddit
The problem is in the Widget.ts module, which imports all the components and returns the one specified by child.type argument in getWidgetType( ...
Read more >
Using WPF to Visualize a Graph with Circular Dependencies
Reviews a WPF application that displays an object graph which can be rearranged by the user at runtime, and highlights circular dependencies ......
Read more >
HTML DOM Canvas Object - W3Schools
This reference will cover the properties and methods of the getContext("2d") object, which can be used to draw text, lines, boxes, circles, ...
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