Skip to content

Build Error: Selector ":root,:host" is not pure (nextjs/postcss) #16725

Closed
@gene-git

Description

@gene-git

versions:

   node: '23.8.0',
    "@tailwindcss/typography": "^0.5.16",
    "@tailwindcss/postcss": "^4.0.8",
    "tailwindcss": "^4.0.8"
    "postcss": "^8.5.3",

     npm: '11.1.0',
    "next": "^15.1.7",
    "react": "^19.0.0",

While I have not changed any code of mine, it is always possible there's something I am not doing correctly. That said here's what I am seeing.

Issue:

Our current production server is running tailwindcss 4.0.6 and postcss 8.5.2 with same versions of next and react and builds and runs without problems.
After updating to above versions, I am now getting this error when building

./src/app/page.module.css:2:14
Syntax error: Selector ":root,:host" is not pure (pure selectors must contain at least one local class or id)

The file page.module.css is the file imported to provide css everwhere.
It contains:

 @reference "./globals.css";

/* shared css defined below */
.container {
    @apply md:flex ...
}
all common definitions in same file

globals.css contains:

@import 'tailwindcss';
@plugin "@tailwindcss/typography";

@layer base {
  *,
  ::after,
  ::before,
  ::backdrop,
  ::file-selector-button {
    border-color: var(--color-gray-200, currentColor);
  }
}


@theme {
   --shadow-3xl: 0 35px 60px rgba(0, 0, 0, 0.3);
   --shadow-4xl: 0 70px 60px rgba(0, 0, 0, 0.3);
}

When running dev using updated packages, it seems to work fine but when building for production it generates this error:

   Creating an optimized production build ...
<w> [webpack.cache.PackFileCacheStrategy] Skipped not serializable cache item 'Compilation/modules|javascript/auto|xxx/node_modules/next/dist/build/webpack/loaders/next-flight-css-loader.js??ruleSet[1].rules[13].oneOf[5].use[0]!xxx/node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[13].oneOf[5].use[1]!xxx/node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[13].oneOf[5].use[2]!xxx/src/app/page.module.css|rsc': No serializer registered for CssSyntaxError
<w> while serializing webpack/lib/cache/PackFileCacheStrategy.PackContentItems -> webpack/lib/NormalModule -> webpack/lib/ModuleBuildError -> CssSyntaxError
<w> [webpack.cache.PackFileCacheStrategy] Skipped not serializable cache item 'Compilation/modules|javascript/auto|xxx/node_modules/next/dist/build/webpack/loaders/next-flight-css-loader.js??ruleSet[1].rules[13].oneOf[5].use[0]!xxx/node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[13].oneOf[5].use[1]!xxx/node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[13].oneOf[5].use[2]!xxx/src/app/page.module.css|ssr': No serializer registered for CssSyntaxError
<w> while serializing webpack/lib/cache/PackFileCacheStrategy.PackContentItems -> webpack/lib/NormalModule -> webpack/lib/ModuleBuildError -> CssSyntaxError
Failed to compile.

./src/app/page.module.css:2:14
Syntax error: Selector ":root,:host" is not pure (pure selectors must contain at least one local class or id)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions