Skip to content

less.render won't callback @ import-visitor.js line 33 #1987

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

Closed
benpptung opened this issue Apr 22, 2014 · 2 comments
Closed

less.render won't callback @ import-visitor.js line 33 #1987

benpptung opened this issue Apr 22, 2014 · 2 comments

Comments

@benpptung
Copy link

test.less

//@import url("//fonts.googleapis.com/css?family=Lobster|Cabin:400,700"); // line 1
@import url("//use.edgefonts.net/c/950482/alegreya:i4:i7:n4:n7.b6D:N:2,b6G:N:2,b6C:N:2,b6F:N:2/d"); // line 2

test.js:

var less = require('less'),
    fs = require('fs'),
    path = require('path');

fs.readFile(path.join(__dirname, 'test.less'), 'utf8', function(err, content){

  if (err) return console.error('fs-error:', err);

  less.render(content, {paths: [__dirname], filename: 'test.less'}, function(err, css){
    // will not be called if test.less is line 2
    if (err) return console.error('less-error:', err); 
    console.log('less-css:', css);
  });

});

I am not sure how less handle @import url("..."), however, in the above codes,
less will not callback, because it stuck on import-visitor.js line 33, due to
this.importCount is 1 at that time.

If I switch the tess.less to line 1, less.render will go.

@lukeapage
Copy link
Member

work-around is to do this

@import (css) url("//use.edgefonts.net/c/950482/alegreya:i4:i7:n4:n7.b6D:N:2,b6G:N:2,b6C:N:2,b6F:N:2/d");

it seems less is treating it like its a less import because there is no mention of css in the URL. I'll look into why importCount isn't getting decremented.

@lukeapage
Copy link
Member

Okay also fixed the problem, which was that it was trying to fetch the file but erroring because there was no protocol and then the code incorrectly checked error after it checked the result status code. Now it checks error first and it uses http if there is no protocol.

But if you want it to just output the import, you will have to use the (css) option when the filename doesn't end in css.

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

2 participants