2

I have two Less files in the public/stylesheets. I am using Express.js to serve them as CSS files.

The first file, one.less looks like this:

@import "another.less";

h1 {
    color: red;
}

The second file, another.less looks like this:

p {
    color: red;
}

When I try to load the page, the server quits with the error:

file 'another.less' wasn't found.

I have also tried an absolute path, but it didn't work.

This is my Express.js configuration:

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }))
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
});
2
  • 1
    Without knowing 'less', the error is about the file another.less not found, but you provide another.css, is that right? Commented Jan 17, 2012 at 20:20
  • Sorry, those are actually .less files. I fixed it. Thanks for catching that! Commented Jan 17, 2012 at 21:22

2 Answers 2

3

You should be using connect-less for this now. The original less compiler you're using above is a part of connect, actually, and if you check out the current issue list, you'll see that TJ opted to not support less any further in connect due to the compilers being too different (a case of "can't make everyone happy") :

https://github.com/senchalabs/connect/pull/174

You can look up connect-less here : https://github.com/MartinodF/connect-less

I'll put the steps for install here, but understand they could become dated (check the github page if this doesn't work, and let me know and I'll sync up):

Use NPM to install connect-less

npm install connect-less

Then load it in your app, specifying the source (and optionally destination) directory

app.use(require('connect-less')({ src: __dirname + '/public/' }));

This worked flawlessly for me on an armv7/Trimslice linux box with expressjs 2.5.2 and node 6.6

Sign up to request clarification or add additional context in comments.

1 Comment

Works for express 3 and node 10 too
2

Edit: '@import "/public/stylesheets/two";'

Original proposal did not work.

4 Comments

If I use .css, it won't statically import the Less file (i.e. in the compiled CSS, there's a line @import "another.css";. I want to combine the Less files at compile time. Thanks for the idea, though!
Right. Try this one then @import "/public/stylesheets/two";
It worked! Thanks! Unfortunately, it will only re-compile if I update one.less. If I only update another.less, it won't change. Do you know any fix for this?
Not sure about that one, it would require digging into the less compiler probably. Finding out how it currently manages cancelling the cache and extending it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.