Skip to content

bg-conic not working in next.js production builds #17977

Open
@Multiply

Description

@Multiply

What version of Tailwind CSS are you using?
v4.1.6

What build tool (or framework if it abstracts the build tool) are you using?
Next.js 15.3.2

What version of Node.js are you using?
v22.11.0

What browser are you using?
Chrome

What operating system are you using?
macOS

Reproduction URL
https://github.com/Multiply/next.js-tailwind-conic-bug
(based on npx create-next-app@latest for the initial commit)

Describe your issue
In next.js production builds (npm run build -> npm run start) bg-conic's background-image does not work.
It works fine in development builds npm run dev.

My initial thoughts would be that it's a @layer issue, but I haven't played too much with it yet, to really debug it further.

Activity

wongjn

wongjn commented on May 12, 2025

@wongjn
Collaborator

Debugged the difference with @tailwindcss/cli --minify. The key difference stopping it from working is:

+++ Next.js
--- @tailwindcss/cli
 @property --tw-gradient-from-position {
   syntax:"<length-percentage>";
   inherits:false;
+  initial-value:0
-  initial-value:0%
 }

It seems like some extra CSS minifier strips the percentage sign from the above @property value, causing the gradient to stop working.

You can workaround this by adding the class name from-0% but probably not ideal.

Multiply

Multiply commented on May 12, 2025

@Multiply
Author
  • initial-value:0
  • initial-value:0%
    It seems like some extra CSS minifier strips the percentage sign from the above @property value, causing the gradient to stop working.

I noticed this initially, and assumed 0 was an accepted value for syntax: "<length-percentage>";
It seems like it does this for other values as well.

RobinMalfait

RobinMalfait commented on May 12, 2025

@RobinMalfait
Member

Hey!

This is happening because of a minifier used in Next.js. As a workaround, you could add this workaround to your next.config.js file:

const nextConfig = {
  webpack(config) {
    // Disable CSS minification
    config.optimization.minimizer = config.optimization.minimizer.filter((fn: any) => {
      return !fn.toString().includes("CssMinimizerPlugin");
    });

    return config;
  },
}
module.exports = nextConfig

Or use ESM / TypeScript, the important part is the webpack config to remove the CSS minifier.

Multiply

Multiply commented on May 12, 2025

@Multiply
Author

Are there any tickets tracking this issue that you know of, @RobinMalfait?

RobinMalfait

RobinMalfait commented on May 12, 2025

@RobinMalfait
Member

@Multiply not yet, I have to create a minimal reproduction and open an issue, but wanted to give you a workaround in the meantime.

Multiply

Multiply commented on May 12, 2025

@Multiply
Author

Following some breadcrumbs, this might have fixed it?
cssnano/cssnano#1695

Edit:
Seems like nextjs@canary is using cssnano-preset-default@7.0.6 that doesn't contain the above PR, so maybe upgrading to 7.0.7 could do something.

RobinMalfait

RobinMalfait commented on May 12, 2025

@RobinMalfait
Member

That might fix it, but I also think that Next.js is bundling the dependency instead of relying on it as an actual dependency. They also use cssnano-simple: https://github.com/vercel/next.js/tree/canary/packages/next/src/bundles/cssnano-simple

Multiply

Multiply commented on May 12, 2025

@Multiply
Author

That might fix it, but I also think that Next.js is bundling the dependency instead of relying on it as an actual dependency. They also use cssnano-simple: https://github.com/vercel/next.js/tree/canary/packages/next/src/bundles/cssnano-simple

Yes, that's where I got the above package from, as they include that in there.

Multiply

Multiply commented on May 12, 2025

@Multiply
Author

As a follow-up, I'm confident the PR I referenced earlier does not fix the underlying issue. It's only about <percentage> and quotes around it, it doesn't affect <length-percentage>. (See my comment here: cssnano/cssnano#1695 (comment))

I'd assume if we just add one more condition there, it'll be solved.

Edit: I've added a PR to solve it here: cssnano/cssnano#1702

RobinMalfait

RobinMalfait commented on May 13, 2025

@RobinMalfait
Member
sumansuhag

sumansuhag commented on May 13, 2025

@sumansuhag
SilvioDoMine

SilvioDoMine commented on Jun 7, 2025

@SilvioDoMine

This issue is happening on Nuxt.js production builds as well

IsmeetKachhap007

IsmeetKachhap007 commented on Jun 19, 2025

@IsmeetKachhap007

Workarounds and Solutions Disable CSS Minification in Next.js You can disable the problematic CSS minifier in your Next.js production build by modifying your next.config.js file:-
// next.config.js
const nextConfig = {
webpack(config) {
// Remove the CSS minifier (CssMinimizerPlugin) that breaks conic gradients
config.optimization.minimizer = config.optimization.minimizer.filter((fn) => {
return !fn.toString().includes("CssMinimizerPlugin");
});
return config;
},
};
module.exports = nextConfig;
This disables CSS minification, which prevents the percentage sign from being stripped and allows bg-conic to work as expected in production.

This might work.

devmuhnnad

devmuhnnad commented on Jun 24, 2025

@devmuhnnad

Manually patch the output CSS file (post-build hook)

If you want to keep minification but fix the bug, you can patch the final output file via a custom Node script after build.

scripts/patch-css.js

import fs from 'fs';
import path from 'path';

const cssDir = './.next/static/css';

fs.readdirSync(cssDir).forEach(file => {
  if (file.endsWith('.css')) {
    const filePath = path.join(cssDir, file);
    let content = fs.readFileSync(filePath, 'utf8');

    // Patch initial-value: 0 to 0% only for --tw-gradient-from-position
    content = content.replace(
      /@property\s+--tw-gradient-from-position\s*\{([^}]*?)initial-value:\s*0([^%])/,
      (_, pre, post) => `@property --tw-gradient-from-position {${pre}initial-value: 0%${post}`
    );

    fs.writeFileSync(filePath, content, 'utf8');
    console.log(`✔ Patched ${file}`);
  }
});

Run this after build:

"scripts": {
  "build": "next build && node scripts/patch-css.js"
}

✅ This ensures the CSS is fixed after all minification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Multiply@RobinMalfait@wongjn@SilvioDoMine@devmuhnnad

        Issue actions

          bg-conic not working in next.js production builds · Issue #17977 · tailwindlabs/tailwindcss