This error occurs when a custom naming function fails while it generates a
name. The message shows which kind of name it was generating and the error from
the function. The compiler does not invent a name in its place.
Reported
import { defineConfig } from "stillwind/config";
export default defineConfig({
projects: [
{
css: "./src/stillwind.css",
files: ["src/**/*.tsx"],
namingRevision: "1",
naming: {
utilityClass(context, hash) {
if (!context.module.endsWith("Button.tsx")) {
throw new Error("Only Button.tsx is supported");
}
return `button_${hash.toString("hex")}`;
},
},
},
],
});style("p-4");SW03002: identifier generation failed for class: Error: Only Button.tsx is supported
Fixed
import { defineConfig } from "stillwind/config";
export default defineConfig({
projects: [
{
css: "./src/stillwind.css",
files: ["src/**/*.tsx"],
namingRevision: "2",
naming: {
utilityClass(context, hash) {
if (!context.module.endsWith("Button.tsx")) {
return null;
}
return `button_${hash.toString("hex")}`;
},
},
},
],
});style("p-4");The custom name still applies to Button.tsx. Other modules use default names.
How to fix
- Reproduce the request from the message, and fix the function so that it returns
a name or
nullto keep the default name. - Keep the function pure: the same request must always produce the same name.
- Change
namingRevisionwhenever you change the function.