Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with @import from subfolder on parent folder #590

Closed
sindresorhus opened this issue Jan 22, 2012 · 2 comments
Closed

Issue with @import from subfolder on parent folder #590

sindresorhus opened this issue Jan 22, 2012 · 2 comments

Comments

@sindresorhus
Copy link
Contributor

I have this file structure:

- test.js
- subfolder
    - test.less
    - subfolder2
        - test2.less

test.js

var fs = require('fs');
var file = fs.readFileSync('subfolder/test.less', 'utf-8');
require('less').render( file, function(e, css) {
    console.log(css);
});

test.less

@import 'subfolder/test2';

test2.less is empty.


When I run node test.js, I get this error:
file 'subfolder/test2.less' wasn't found.

The issue is that since we read the file in as a string, LESS doesn't know the context.

Maybe the .render method should also accept a context parameter?

Like:

var context = 'subfolder';
require('less').render( file, function(e, css) {
    console.log(css);
}, context );

Or let the first argument to the .render method also accept; a path to a file to render or a file buffer?

@neonstalwart
Copy link
Contributor

i think #331 is a pull request for a test that shows that this fails in less

@lukeapage
Copy link
Member

render takes a second argument which is an object of options.

If you set the paths property in there to [path] then it will use that path to try to find imports.

e.g.

require('less').render( file, {paths: ["subfolder/"]}, function(e, css) {

I think that's what you are getting at.. but your example is wrong subfolder/test2.less doesn't exist.. subfolder2/test2.less does, so is that significant?

is it significant that the import is empty?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants