{"action":"created","issue":{"url":"https://api.github.com/repos/sass/node-sass/issues/670","labels_url":"https://api.github.com/repos/sass/node-sass/issues/670/labels{/name}","comments_url":"https://api.github.com/repos/sass/node-sass/issues/670/comments","events_url":"https://api.github.com/repos/sass/node-sass/issues/670/events","html_url":"https://github.com/sass/node-sass/issues/670","id":57509757,"number":670,"title":"Custom importer fails silently if you return a buffer","user":{"login":"callumlocke","id":250617,"avatar_url":"https://avatars.githubusercontent.com/u/250617?v=3","gravatar_id":"","url":"https://api.github.com/users/callumlocke","html_url":"https://github.com/callumlocke","followers_url":"https://api.github.com/users/callumlocke/followers","following_url":"https://api.github.com/users/callumlocke/following{/other_user}","gists_url":"https://api.github.com/users/callumlocke/gists{/gist_id}","starred_url":"https://api.github.com/users/callumlocke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/callumlocke/subscriptions","organizations_url":"https://api.github.com/users/callumlocke/orgs","repos_url":"https://api.github.com/users/callumlocke/repos","events_url":"https://api.github.com/users/callumlocke/events{/privacy}","received_events_url":"https://api.github.com/users/callumlocke/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-02-12T19:46:53Z","updated_at":"2015-02-12T23:51:34Z","closed_at":null,"body":"With custom importers, it seems you have to return the file contents as a string. If you return a buffer, then node-sass acts as if you didn't return any contents at all, i.e. it reads the file from disk (bypassing any preprocessing you might have wanted to do in your custom importer). This leads to confusing bugs far away from the cause of the problem.\r\n\r\nIt would be good if custom importers could return a buffer as well as a string. Alternatively, node-sass could error out when an importer returns contents not as a string"},"comment":{"url":"https://api.github.com/repos/sass/node-sass/issues/comments/74178863","html_url":"https://github.com/sass/node-sass/issues/670#issuecomment-74178863","issue_url":"https://api.github.com/repos/sass/node-sass/issues/670","id":74178863,"user":{"login":"callumlocke","id":250617,"avatar_url":"https://avatars.githubusercontent.com/u/250617?v=3","gravatar_id":"","url":"https://api.github.com/users/callumlocke","html_url":"https://github.com/callumlocke","followers_url":"https://api.github.com/users/callumlocke/followers","following_url":"https://api.github.com/users/callumlocke/following{/other_user}","gists_url":"https://api.github.com/users/callumlocke/gists{/gist_id}","starred_url":"https://api.github.com/users/callumlocke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/callumlocke/subscriptions","organizations_url":"https://api.github.com/users/callumlocke/orgs","repos_url":"https://api.github.com/users/callumlocke/repos","events_url":"https://api.github.com/users/callumlocke/events{/privacy}","received_events_url":"https://api.github.com/users/callumlocke/received_events","type":"User","site_admin":false},"created_at":"2015-02-12T23:51:34Z","updated_at":"2015-02-12T23:51:34Z","body":"> I thought your initial suggestion was node-sass to convert the fs buffer to string?\r\n\r\nYes, but I understand you don't want to coerce it, and I'm happy to just call `done({contents: buf.toString()})` myself. \r\n\r\n> Keeping node-sass as dumb as possible and letting LibSass originating errors is a good thing.\r\n\r\nI totally agree in general, but the problem here is libsass *doesn't* originate any error if you pass it a buffer. It just behaves as if you passed it nothing, in which case, by design, it reads the file again from disk (this time bypassing your importer). So everything appears to be working fine – your importer is getting invoked, and the Sass is building without errors, but really it's not working at all. It's a very sneaky bug, that's why I think it's worth doing a quick type check in this particular case, i.e.\r\n\r\n```js\r\nif (data.contents && typeof data.contents !== 'string') {\r\n  throw new TypeError('Expected contents to be a string');\r\n}\r\n```\r\n"}}