Urgent.News

What's breaking now, across thousands of outlets.

Tech

Why React components from npm render unstyled with Tailwind v3

Install a React component library, import a Button , render it. The label shows up and the click handler fires, but the thing looks like a gray browser default. The console is quiet and the build is green. I reproduced this in clean projects while working on MoonUI, a component library built on Radix and Tailwind. The components were not broken. My Tailwind setup just had no idea they existed,…

React components from npm libraries often render unstyled when used with Tailwind v3. This occurs because Tailwind v3 generates CSS only for the class names it can see. When a component library ships its Tailwind classes inside compiled JavaScript, those classes are not found by Tailwind's configuration unless explicitly included.

To resolve this issue, you need to add the library's distribution folder to the `content` array in your `tailwind.config.js`. For example, if the library is named `@moontra/moonui` and its compiled files are in the `dist` folder, you should add `./node_modules/@moontra/moonui/dist/**/*.{js,mjs}` to the `content` array. This ensures Tailwind scans the necessary files and applies the appropriate classes.

Additionally, some libraries may use CSS variables to define colors and other design tokens. In such cases, you need to import the token file provided by the library. For instance, for the `@moontra/moonui` library, you would import `@moontra/moonui/tokens.css` using either an import statement in your main file or a global import in your layout file. This step is crucial for applying the correct colors and styles to the components.

Once you have configured Tailwind to include the library's files and token file, the components should render with the expected styles. It is important to note that the order in which these steps are taken can affect the outcome. For example, adding the library's files to `content` without importing the token file may lead to components with missing colors.

Conversely, importing the token file without including the library's files in `content` may not resolve the issue if the components rely on class names defined in the library's files.

In summary, to fix unstyled components from npm libraries when using Tailwind v3, you need to add the library's distribution folder to the `content` array in your `tailwind.config.js`, and import the token file provided by the library. Ensuring these steps are taken in the correct order will help you achieve the desired styling for the components.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

To Touch Grass

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 1: Touch Grass What I Built Nothing. Instead, I went outside to touch grass with my family.

OpenTelemetry-Style Spans for VIN Decode Latency and Upstream Attribution

A free VIN decode looks like one button click. Under the hood it is normalize, validate, cache lookup, optional proxy hop, NHTSA DecodeVinValues, field mapping, and render.

  • Implement OpenTelemetry-style spans for VIN decode latency.
  • Use child spans to pinpoint slow stages: normalization, cache, upstream VPIC, mapping.
  • Add hashed VIN attribute for privacy-safe identification.

More from Wednesday 7 October →