Minification failed. Returning unminified contents

I resolved the problem bundling bootstrap.css by doing 2 things:

  1. Include the bootstrap.css first in the bundle. The code sample in the question already does this, but I was not.
  2. Add the official minified version (bootstrap.min.css) to the project in the same directory as the unminified version. This prompts the bundler to use the existing minified file instead of trying (and failing) to minify bootstrap.css itself. See the green arrow in the screenshot below.

Note that if you are using a specific theme, substitute bootstrap.css and bootstrap.min.css with the files provided by the theme. Here's the working code from my project that uses the spacelab theme:

            bundles.Add(new StyleBundle(GetStyleBundlePath("bootstrap")).Include(
            "~/Content/3rdParty/bootstrap.spacelab.css",
            "~/Content/3rdParty/bootstrap-datepicker.css",
            "~/Content/3rdParty/bootstrap-multiselect.css"));

enter image description here


We experienced the same issue and it turns out that bootstrap.css is the problem. We were getting the same exact minification errors that you wrote above. The bundler is having problems with @import, @keyframes and @-webkit-keyframes that are in the css file.

What we did to solve the problem is to remove bootstrap.css from the bundle and just reference it directly (or the minified version, if you have it) in the Shared/_Layout.cshtml.

@Styles.Render("~/Content/bootstrap.min.css")
@Styles.Render("~/Content/css")

Make sure the none of those .js files you are bundling end with //Some Comment. If a file ending with a double backslash // comment is tacked on to another dependent file it will be seen as one long comment causing the error you are seeing. I bet there is an //@Import at the end of one of your .js files. If that's the case I think you can probally safely change that line to /*@Import */

Also, I don't know if this was fixed in MVC5 but in MVC4 the minification parser doesn't handle the non-standard :-moz-any() and :-webkit-any() css tags.

Also look at this post that details how to resolve Less @import directories.


For those that may stumble on this post... You can also resolve this by moving the @import to the first bundled item.

According to: http://webdesign.about.com/cs/css/qt/tipcssatimport.htm

@Import must always be first in the CSS document. When you bundle multipule CSS files together, it chains them into a single bundled css file. Since the second css file added to my bundle, in bundle config, contained an @Import at the start, as the files were chained together the @import appeared towards the middle of the newly merged document. Once I changed the bundle order the issue was resolved.

This is important to understand because although you can use the minified files provided by plugins like bootstrap any changes made to the non-minified files during development will not be added to the existing minified css file. Meaning you will have to make the changes twice, and navigate your way through the minified file.