Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
loadConfig
✓ import { loadConfig } from 'tailwind-api-utils';
✗ const loadConfig = require('tailwind-api-utils').loadConfig;
The library primarily uses ESM; CJS require is possible but less idiomatic for modern TypeScript/Node.js projects.
sortClassname
✓ import { sortClassname } from 'tailwind-api-utils';
✗ import sortClassname from 'tailwind-api-utils/sortClassname';
Functions are named exports from the main package entry point.
Config
✓ import type { Config } from 'tailwind-api-utils';
Type imports should be used for better type-checking and bundle optimization.
Demonstrates loading a Tailwind CSS configuration and sorting a string of class names using the library's utilities, compatible with Tailwind CSS v3 and v4 configurations.
import { loadConfig, sortClassname } from 'tailwind-api-utils';
import path from 'path';
import process from 'process';
// A dummy Tailwind CSS configuration file content for demonstration
const tailwindConfigFileContent = `
module.exports = {
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {},
},
plugins: [],
};
`;
async function runExample() {
// In a real application, you would load your actual tailwind.config.js
// For this example, we'll simulate a config file.
// This path needs to be valid in the execution environment.
const dummyConfigPath = path.join(process.cwd(), 'tailwind.config.js');
// You might write this content to a temporary file if truly testing `loadConfig`
// For simplicity, `loadConfig` tries to find it, so ensuring it exists is key.
try {
// Load the Tailwind config. This will look for tailwind.config.js by default.
// Make sure 'tailwindcss' is installed as a peer dependency.
const config = await loadConfig({ configPath: dummyConfigPath });
console.log('Loaded Tailwind config:', config.theme.extend);
const classesToSort = 'p-4 text-lg font-bold mx-auto flex items-center bg-blue-500 rounded-md';
const sortedClasses = sortClassname(classesToSort, config);
console.log('Original classes:', classesToSort);
console.log('Sorted classes:', sortedClasses);
const v4Classes = 'group/item:hover:p-4 md:text-xl sm:flex-row';
const sortedV4Classes = sortClassname(v4Classes, config);
console.log('Original v4 classes:', v4Classes);
console.log('Sorted v4 classes (with v4 compatibility):', sortedV4Classes);
} catch (error) {
console.error('Failed to run example:', error);
console.warn('Ensure `tailwindcss` is installed as a peer dependency.');
console.warn('For `loadConfig` to work, a `tailwind.config.js` file (or specified path) must be resolvable.');
}
}
runExample();
Errors
Common errors & fixes
Error: Cannot find module 'tailwindcss'
The `tailwindcss` package is a peer dependency and was not installed in the project.
fixInstall Tailwind CSS: `npm install tailwindcss` or `yarn add tailwindcss`.
TypeError: Cannot read properties of undefined (reading 'theme')
The `loadConfig` function likely failed to load a valid Tailwind CSS configuration, resulting in an undefined or malformed config object.
fixEnsure `tailwind.config.js` exists and is valid at the expected path, or provide an explicit `configPath` to `loadConfig`.
SyntaxError: Cannot use import statement outside a module
Attempting to use `import` syntax in a CommonJS (`.js` without `"type": "module"` in `package.json`) Node.js environment.
fixEither convert your project to use ES Modules by adding `"type": "module"` to `package.json` or use dynamic `import()` or switch to `require()` if the library provides a CJS entry (though for `tailwind-api-utils`, ESM is preferred).
Audit
Dependencies
tailwindcssrequiredRequired for accessing the Tailwind CSS API and configuration; it's a peer dependency.