0

I am trying to use Promises with less.render in Node.js, but I am not getting the CSS returned that I would expect.

Here is the result I am getting:

{ domain: null, _events: {}, _maxListeners: 10 }

And this is the code block I am using:

var q = require("q")  
  , less = require("less")  
  ;

var less_css = "@background: #131313; body{background:@background;}";

q.resolve( less.render(less_css) )
  .then(function(output_css) {

    // [UNEXPECTED RESULTS]
    console.log(output_css);

  },function (error) {
    console.log('Error: ', error);
  });

However, when I do it without the promises (as a regular old callback), it works...

var less = require("less");  

var css = "@background: #131313; body{background:@background;}";  

less.render(css, function(err, css_output){  
  console.log( css_output );  
});  

This block outputs the following css, which is what I was expecting from the promise:

body {
  background: #131313;
}

Any help appreciated. Thanks :)

f1lt3r
  • 2,176
  • 22
  • 26
  • Update: Things worked as expected when switching to less version 2.0.0-b1. See more details here: https://github.com/less/less.js/issues/2271#issuecomment-61762681 – f1lt3r Nov 05 '14 at 12:57
  • After reading B. Gruenbaum's answer, I got the following code to work with less@1.7.5. var Promise = require("bluebird"), less = require("less"); function renderLess(css){ return new Promise(function(resolve,reject){ less.render(css,function(err,data){ if(err !== null) return reject(err);; resolve(data); }); }); } var stuff = Promise.resolve(renderLess(css)) .then(function(css_output){ console.log(css_output); }, function(err){}); – f1lt3r Nov 05 '14 at 19:00

0 Answers0