LESS files intermittently not being included in Bundle - asp.net

In my ASP.NET MVC5 project I'm using Bundling/Minification and dotless together.
var commonCss = new StyleBundle("~/bundles/main.css").Include(
"~/CSS/global.css",
"~/CSS/header.less",
"~/CSS/footer.css"
);
commonCss.Transforms.Clear();
commonCss.Transforms.Add(new LessTransform());
commonCss.Transforms.Add(new ConfigurableStyleTransform(cssSettings));
return commonCss;
LessTransform() is from System.Web.Optimization.Less.
Intermittently I'm seeing the header.less file not being included in the bundle. Sometimes it will, sometimes it won't, without any code changes.
I've ran the LESS file through a validator and no issues found.
The only other times I've seen a file not being included in a bundle is when the file cannot be found, or theres a syntax issue. However this doesn't seem applicable for this instance.
What possible reasons are there for this file not being included in the bundle?

You might be hitting this bug in dotless. If that's the case, until it gets fixed, you can get around it by specifying disableParameters="true" in the dotless section of your Web.config.

Related

Meteor including bootstrap and jQuery

I get an error as soon as I add jQuery and Bootstrap. The three files that I add are
1) a_jquery-1.11.2.min.js // so that it is processed before 'b' in bootstrap
2) bootstrap.min.css
3) bootstrap.min.js
and they are located in /lib.
If I add bootstrap without jQuery, I get an error saying that Bootstrap needs jQuery. After I add jQuery I get the following error messages.
/Users/username/.meteor/packages/meteor-tool/.1.0.40.cbg34i++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:173
throw(ex);
^
TypeError: Cannot call method 'createElement' of undefined
at jb (app/lib/a_jquery-1.11.2.min.js:2:7547)
at app/lib/a_jquery-1.11.2.min.js:2:22045
at app/lib/a_jquery-1.11.2.min.js:2:22746
at c (app/lib/a_jquery-1.11.2.min.js:2:207)
at app/lib/a_jquery-1.11.2.min.js:2:212
at app/lib/a_jquery-1.11.2.min.js:6:3
at /Users/username/my_app/.meteor/local/build/programs/server/boot.js:205:10
at Array.forEach (native)
at Function._.each._.forEach (/Users/username/.meteor/packages/meteor-tool/.1.0.40.cbg34i++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
Does anyone know what I am missing?
EDIT: I also have a question about including the stylesheets. I include a CDN bootstrap in /client/views/layout.html but as soon as I delete the importing line and save a local bootstrap.min.css file in /lib the styles start breaking. Why does this happen?
The /lib folder is for shared code, putting client-side frameworks in it will cause you a lot of trouble since Meteor will try to run it on the server too (and miserably fail at finding a window object). Place any client-only code in the client folder instead.
Plus, I would suggest taking a look at packages rather than doing it yourself, a lot of people have already done what you're going through.
If you want to have local style sheets, either put them in the client folder (loaded immediately) or in the public folder (for delayed loading via an import). More about special folders in the documentation.
You can't put them in /lib since anything in there is also loaded by the server. /client/lib would be okay.
Note also that you don't need jQuery, that comes by default (it's used by Blaze).
Finally, I'd recommend using a bootstrap package. If you use this one then you'll by able to make use of all the mixins and also change the base varaibles cleanly. See this article for more information.

edit sass-rails config options

I am getting really confused about configuring Sass config options. Basically I want to disable the line comments in the compiled css file. So I went in and created a sass.rb in the Initializers folder with the following line:
Rails.application.config.sass.line_comments = true
I then restart my apache server and check in Safari web developer, my css file still contains the comments like /* line## /path/to/css/file */ above every css statement. I then test it in Firefox and open Firebug, and I don't see those line comments there, which suggest inconsistent browser behavior.
So I go back to my initializer sass.rb file and turn on line_comments, restart the web server and try again, this time I get the exact same result as before, nothing's changed, that basically tells me either that's specific to the browsers, there's a problem with the setting scope/syntax, or there's a caching issue (I'm working in development, so there shouldn't be any caching, right?). I'd really appreciate if someone can provide some insight on this. Thanks.
EDIT: The proposed solution to make a change to the sass file(s) didn't solve anything so I doubt it is the same problem.
Note: I am using sass with rails and I am getting separate css files for each of my sass files, which doesn't seem very right...
The problem was a combination of needing to set config.assets.debug to false for development, setting config.assets.compress to true, and probably a better understanding of sass compilation.

Minification failed. Returning unminified contents

I have made my first website using MVC 5 which works fine on my local machine but when I publish it to the server some of the CSS is not minifying correctly.
/* Minification failed. Returning unminified contents.
(80,1): run-time error CSS1019: Unexpected token, found '#import'
(80,9): run-time error CSS1019: Unexpected token, found 'url('../Content/dark-skin/skin.css')'
(671,16): run-time error CSS1062: Expected semicolon or closing curly-brace, found ':'
(1288,16): run-time error CSS1062: Expected semicolon or closing curly-brace, found ':'
(1680,1): run-time error CSS1019: Unexpected token, found '#keyframes'
(1682,5): run-time error CSS1062: Expected semicolon or closing curly-brace, found '50%'
(1685,1): run-time error CSS1019: Unexpected token, found '#-webkit-keyframes'
(1687,5): run-time error CSS1062: Expected semicolon or closing curly-brace, found '50%'
*/
/* NUGET: BEGIN LICENSE TEXT
*
* Microsoft grants you the right to use these script files for the sole
* purpose of either: (i) interacting through your browser with the Microsoft
* website or online service, subject to the applicable licensing or use
* terms; or (ii) using the files as included with a Microsoft product subject
* to that product's license terms. Microsoft reserves all other rights to the
* files not expressly granted by Microsoft, whether by implication, estoppel
* or otherwise. The notices and licenses below are for informational purposes only.
*
* NUGET: END LICENSE TEXT */
/*!
* Bootstrap v3.0.0
*
* Copyright 2013 Twitter, Inc
* Licensed under the Apache License v2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Designed and built with all the love in the world by #mdo and #fat.
*//*! normalize.css v2.1.0 | MIT License | git.io/normalize */
After trying to correct some of the errors and publishing again the error looks the same.
The strangest part is with bootstrap.css which I have slightly modified for the purpose of the website. When I publish it the changes are not in the bundle file. Is it possible that bootstrap is loaded from Bootstrap server and not my project?
bundles.Add(new StyleBundle("~/Content/cssmain").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/ilightbox.css",
"~/Content/bannerscollection_zoominout.css"));
I have also tried to do minification myself using web application but my changes are not visible and the files do not appear to be minified.
Any help is appreciated.
I resolved the problem bundling bootstrap.css by doing 2 things:
Include the bootstrap.css first in the bundle. The code sample in the question already does this, but I was not.
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"));
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.
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.
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")
Minification Problem Solution:
I know Two types of possible that cause optimization problem :
The invalid CSS files that should be validated before bundling. here is W3C CSS validation service to meet this purpose.
Also considering that Microsoft Optimizer reads content of target resources for minification process, so by using some special phrases like # sourceMappingURL=jquery.min.map in a JavaScript file or #charset "UTF-8"; in a styleSheet file, the Minification will be failed again. So try to remove or comment them.
Note that by default, Bundling process can't build relative path of image resources in css or js files.
Relative Image Path Solution:
You can use the same path as bundling path like:
bundles.Add(new StyleBundle("~/Content/css/jquery-ui/bundle")
.Include("~/Content/css/jquery-ui/*.css"));
Where you define the bundle on the same path as the source files that made up the bundle, the relative path of image resources will still work( i.e. /bundle can be any name you like).
Or using new CssRewriteUrlTransform() as second parameter like:
bundles.Add(new StyleBundle("~/Content/css/bundle")
.Include("~/Content/css/*.css", new CssRewriteUrlTransform()));
Encountered this too. I had Bootstrap in the bundle-list among with the main CSS file, in which I imported bootstrap.min.css again. So Bootstrap got requested twice. Removing the import line in my main CSS file solved this for me.
#import don't work with bundle minification.
Do this... in the file BundleConfig.cs set:
bundles.UseCdn = true;
bundles.Add(new StyleBundle("~/skin", "../Content/dark-skin/skin.css"));
And set this in layout:
#Styles.Render("~/skin")
But only application relative URLs (~/url) are allowed.
What I did was, in my BundleConfig.vb (cs), I put all the files I referenced by #import within the css files like this:
bundles.Add(New StyleBundle("~/bundle/css-account") _
.Include("~/Content/consola/bootstrap/css/bootstrap.css",
"~/Content/consola/plugins/node-waves/waves.css",
"~/Content/consola/plugins/animate-css/animate.css", //Referenced by #import
"~/Content/consola/plugins/bootstrap-select/css/bootstrap-select.css",
"~/Content/account/account.css",
"~/fonts/awesome/css/font-awesome.css",//Referenced by #import
"~/Content/consola/materialize.css", //Referenced by #import
"~/Content/consola/style.css"))
That eliminated almost all the errors.
The next thing I did was modify my css files changing css pseudo-classes syntax from this [type="checkbox"]:not(.filled-in, .gm-menu-hamburger) + label:after { to this one [type="checkbox"]:not(.filled-in) + label:after,
[type="checkbox"]:not(.gm-menu-hamburger) + label:after {
That solved all errors I had.
Hope that helps
The issue for me was I had #import in a .css file.
I moved my code into a corresponding .less file that gets compiled on build, which resolved the build error for me. Compiled with Gulp.
Not sure about other, but changes I made in Bundle.config file did not get picked up until I rebuild the project.
I guess, compiler includes the information into the compiled DLL, and no longer looks at Bundle.config.
I am using ASP.NET forms application though, not sure about MVC.
Check if you have any minified (...min.js) files in your bundle.
bundles.Add( ... minified files???
));
Remove them from the bundle and render in the _layout.cshtml file:
#Styles.Render("~/Content/fontawesome-free-5.10.1-web/css/all.min.css")
Or add the non minified version of your css to the bundle.
My solution was the same as #GraehamF, I was having issues where the #imports were trying to load the css, when you inspect with dev tools the bundle css's if you see something like "run-time error", it means the file is not loaded correctly.
Before to deploy remove the debug="true" on your web.config then try to run the code on your local box, that should give you the idea of which files are not getting loaded and causing the bundle did not work.

Updated CSS not appearing in merged file

A skin.css file has been updated on a DotNetNuke website, but the updated change to the file has not yet come through on the main css file.
Tried clearing the cache within DNN and no luck...
I'm not overly familiar with DNN and how it works, but isn't it supposed to get merged into the rest of the CSS files with the DependencyHandler.axd. This does not seem to have happened.
Anyone any ideas?
When you say it isn't showing up in the Main.CSS file, I am going to assume you are using the CDF functionality in the platform. If so, you can go to the Host/Host Settings page, and look for the Client Dependency Framework portion of the settings.
In those settings you can "increase" the version number, which should cause the files to be regenerated, you can also turn off CDF to allow DNN to just load the CSS and JS files normally which generally makes debugging things a little bit easier.

.less file fails to compile when using variables from another file

I have a .less file that contains a few definitions that make use of variables that are defined in another file.
Example:
body {
font-family: #baseFontFamily;
font-size: #baseFontSize;
color: #textColor;
}
Initially, IntelliJ showed the variables as undefined. When I compiled with Lessc I'd get an error that read as such:
TypeError: Cannot call method 'charAt' of undefined
at getLocation (C:\PATH\npm\node_modules\less\lib\less\parser.js:212:34)
at new LessError (C:\PATH\npm\node_modules\less\lib\less\parser.js:221:19)
at Object.toCSS (C:\PATH\npm\node_modules\less\lib\less\parser.js:385:31)
at C:\PATH\npm\node_modules\less\bin\lessc:107:28
at C:\PATH\npm\node_modules\less\lib\less\parser.js:434:40
at C:\PATH\npm\node_modules\less\lib\less\parser.js:94:48
at C:\PATH\npm\node_modules\less\lib\less\index.js:116:17
at C:\PATH\npm\node_modules\less\lib\less\parser.js:434:40
at C:\PATH\npm\node_modules\less\lib\less\parser.js:94:48
at C:\PATH\npm\node_modules\less\lib\less\index.js:116:17
After doing a little reading I determined that this means there is an error somewhere up in my code. I naturally assumed it was due to the variable definition not working. I commented the lines with variables out, and lessc would compile my project fine.
However, even after I added the appropriate #import so that the variables were defined (and the lines with variables uncommented), I again received the compile-time error. Is there something I'm missing?
Issue discovered. There was 'config.less' file in the parent and child folders. Moving the contents of the config.less from the child to the parent version solved the issues I was experiencing.
I discovered the answer. I tried compiling just the one file (and not the suite of .less files). NPM showed that it was having issues locating one of the Mixins used. Upon #import-ing the proper file, the suite now compiles fine.
Here is the lesson:
- if you are having issues with one of your .less files, try compiling it by itself. NPM will give you more detail about the error than just a general stack trace.
I get these errors as well when i work like this, but the actual compiled css works just fine. I do compile my less on development and only put the css on runtime though, as i do not want styles to be depending on javascript...

Resources