Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

What should an importer function do if the requested file cannot be found? #632

Closed
callumlocke opened this issue Jan 19, 2015 · 7 comments
Closed

Comments

@callumlocke
Copy link

Say my custom importer function is called, asking for something called 'foo', and I determine that the file does not exist (i.e. the @import 'foo' is an error)...

I should be able to call done in some special way to explicitly indicate that the requested file does not exist, causing libsass to call my error callback with an appropriate error object (including the line number of the bad @import).

Something like done(false) or done({file: false}) would be good.

@browniefed
Copy link

done({contents: ''}) ?

@callumlocke
Copy link
Author

That would appear to libsass as if the file does exist and it's just empty.
That's not the same thing.
On Mon, 19 Jan 2015 at 19:30, Jason Brown notifications@github.com wrote:

done({contents: ''}) ?


Reply to this email directly or view it on GitHub
#632 (comment).

@browniefed
Copy link

@callumlocke sorry thought you were asking to make it not error out.

@am11
Copy link
Contributor

am11 commented Jan 19, 2015

Sorry I am lost, what exactly is the requirement here?

Currently libsass produces the error if you only return the non-existing file from custom importer:

Synchronous:

require('node-sass').renderSync({
  data: '@import "foo.scss"',
  importer: function(u,p){
    return {file:"devNull"};
  }
});

// throws the following on stderr

{
  "status": 1,
  "file": "stdin",
  "line": 1,
  "column": 9,
  "message": "file to import not found or unreadable: devNull\nCurrent dir: "
}

Asynchronous:

require('node-sass').render({
  data: '@import "foo.scss"',
  importer: function(u, p, done) {
    done({file:"devNull"})    // you can also return from asynchronous ignoring done
  },
  error: function(e){ console.error(e) }
});

// prints:

{ file: 'devNull' } // this output on console is a workaround for v8/libuv issue, just ignore it.
{ status: 1,
  file: 'stdin',
  line: 1,
  column: 9,
  message: 'file to import not found or unreadable: devNull\nCurrent dir: ',
  code: 1 }

@joshbroton
Copy link

I don't know if this belongs here (I'll also create another issue and post the # here), but when I try to compile using @import url(http://some.external/file) and I don't have internet access, I get this error:

Broken @import declaration of "https://fonts.googleapis.com/css?family=Mr+Dafoe" - timeout

@am11
Copy link
Contributor

am11 commented Jan 29, 2015

@joshbroton, there are two kinds of imports: CSS3 and Sass.
If you have a CSS3 import, the URL will be emitted to the output CSS as is and the browser will take care of the URL.
But in case of Sass import directive, with URL, LibSass does not download any resource from remote computer (see the discussion here: sass/libsass#691). You will need to add custom importer, read the remote resource and pass it along to libsass as data.

@callumlocke, should we close this issue?

@callumlocke
Copy link
Author

I still have a problem, but I think it actually stems from the way libsass has implemented custom importers, and I've started an issue there instead (sass/libsass#862)... if that one ever gets fixed then I might open a clearer issue here :)

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

No branches or pull requests

4 participants