Skip to content

[Next.js 15] CSS Minification fails with "Unclosed block" error during production build #75817

@apiwatja

Description

@apiwatja

Link to the code that reproduces this issue

https://github.com/apiwatja/20250209-css-minification-issue.git

To Reproduce

Reproduction Steps

Create a Next.js 15 project with Tailwind CSS
Install vaul package
Run production build
Build fails during CSS minification

Current vs. Expected behavior

Issue

Production builds fail when CSS minification is enabled in Next.js 15. The error points to an "Unclosed block" issue during the minification process. While direct CSS minification through cssnano works fine, Next.js's built-in minification process fails.

Error Description

During production build (next build), the process fails with a CSS minification error. The error occurs specifically when processing CSS from the vaul package's style.css.

GitHub Action Error:

#18 1.308    ▲ Next.js 15.1.6
#18 1.308    - Environments: .env.local
#18 1.308 
#18 1.381    Creating an optimized production build ...
#18 155.9 Failed to compile.
#18 155.9 
#18 155.9 HookWebpackError: /usr/src/app/static/css/9d611f82b4eb5c2d.css:1:100501: Unclosed block
#18 155.9     at makeWebpackError (/usr/src/app/node_modules/next/dist/compiled/webpack/bundle5.js:28:314608)
#18 155.9     at /usr/src/app/node_modules/next/dist/compiled/webpack/bundle5.js:28:106402
#18 155.9     at eval (eval at create (/usr/src/app/node_modules/next/dist/compiled/webpack/bundle5.js:13:9218), <anonymous>:44:1)
#18 155.9 -- inner error --
#18 155.9 CssSyntaxError: /usr/src/app/static/css/9d611f82b4eb5c2d.css:1:100501: Unclosed block
#18 155.9     at Input.error (/usr/src/app/node_modules/next/node_modules/postcss/lib/input.js:106:16)
#18 155.9     at ScssParser.unclosedBlock (/usr/src/app/node_modules/next/node_modules/postcss/lib/parser.js:574:22)
#18 155.9     at ScssParser.endFile (/usr/src/app/node_modules/next/node_modules/postcss/lib/parser.js:336:35)
#18 155.9     at ScssParser.parse (/usr/src/app/node_modules/next/node_modules/postcss/lib/parser.js:475:10)
#18 155.9     at scssParse (/usr/src/app/node_modules/next/dist/compiled/postcss-scss/scss-syntax.js:1:322)
#18 155.9     at new LazyResult (/usr/src/app/node_modules/next/node_modules/postcss/lib/lazy-result.js:133:16)
#18 155.9     at Processor.process (/usr/src/app/node_modules/next/node_modules/postcss/lib/processor.js:53:14)
#18 155.9     at CssMinimizerPlugin.optimizeAsset (/usr/src/app/node_modules/next/dist/build/webpack/plugins/css-minimizer-plugin.js:48:12)
#18 155.9     at /usr/src/app/node_modules/next/dist/build/webpack/plugins/css-minimizer-plugin.js:79:55
#18 155.9     at async Span.traceAsyncFn (/usr/src/app/node_modules/next/dist/trace/trace.js:153:20)
#18 155.9 caused by plugins in Compilation.hooks.processAssets
#18 155.9 CssSyntaxError: /usr/src/app/static/css/9d611f82b4eb5c2d.css:1:100501: Unclosed block
#18 155.9     at Input.error (/usr/src/app/node_modules/next/node_modules/postcss/lib/input.js:106:16)
#18 155.9     at ScssParser.unclosedBlock (/usr/src/app/node_modules/next/node_modules/postcss/lib/parser.js:574:22)
#18 155.9     at ScssParser.endFile (/usr/src/app/node_modules/next/node_modules/postcss/lib/parser.js:336:35)
#18 155.9     at ScssParser.parse (/usr/src/app/node_modules/next/node_modules/postcss/lib/parser.js:475:10)
#18 155.9     at scssParse (/usr/src/app/node_modules/next/dist/compiled/postcss-scss/scss-syntax.js:1:322)
#18 155.9     at new LazyResult (/usr/src/app/node_modules/next/node_modules/postcss/lib/lazy-result.js:133:16)
#18 155.9     at Processor.process (/usr/src/app/node_modules/next/node_modules/postcss/lib/processor.js:53:14)
#18 155.9     at CssMinimizerPlugin.optimizeAsset (/usr/src/app/node_modules/next/dist/build/webpack/plugins/css-minimizer-plugin.js:48:12)
#18 155.9     at /usr/src/app/node_modules/next/dist/build/webpack/plugins/css-minimizer-plugin.js:79:55
#18 155.9     at async Span.traceAsyncFn (/usr/src/app/node_modules/next/dist/trace/trace.js:153:20)
#18 155.9 
#18 155.9 
#18 155.9 > Build failed because of webpack errors
#18 156.3  ELIFECYCLE  Command failed with exit code 1.
#18 ERROR: process "/bin/sh -c pnpm build" did not complete successfully: exit code: 1

Provide environment information

### Environment
Next.js version: 15.1.6
Node.js version: 22.9.0
Operating System: Linux (Docker container)
Package Manager: pnpm 10.2.1

### Dependencies Related to the Issue
tailwindcss: 4.0.2
postcss: 8.4.35
cssnano: 7.0.6
vaul: 1.1.2 (package containing problematic CSS)

Which area(s) are affected? (Select all that apply)

Webpack

Which stage(s) are affected? (Select all that apply)

Other (Deployed)

Additional context

Additional Context

Direct minification of the CSS files using cssnano works fine
The issue appears to be specific to Next.js 15's built-in minification process
Multiple attempts to configure postcss and cssnano options did not resolve the issue
The error is reproducible in both local and CI/CD environments

Current Workaround

The issue can be worked around by disabling CSS minification in next.config.mjs:

if (!dev) {
  if (!config.optimization) {
    config.optimization = {};
  }
  config.optimization.minimize = false;
  config.optimization.minimizer = [];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    CSSRelated to CSS.linear: nextConfirmed issue that is tracked by the Next.js team.not staleA previously `stale` marked issue that is no longer stale.staleThe issue has not seen recent activity.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions