Skip to content

Commit

Permalink
fix: Errors being swallowed when trying to load node-sass
Browse files Browse the repository at this point in the history
Fixes #563
  • Loading branch information
jhnns committed Jun 1, 2018
1 parent 437450f commit 8000575
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
13 changes: 2 additions & 11 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,8 @@ let asyncSassJobQueue = null;
*/
function sassLoader(content) {
if (asyncSassJobQueue === null) {
let sass;
let sassVersion;

try {
sass = require("node-sass");
sassVersion = /^(\d+)/.exec(require("node-sass/package.json").version).pop();
} catch (e) {
throw new Error(
"Error loading `node-sass`: " + e
);
}
const sass = require("node-sass");
const sassVersion = /^(\d+)/.exec(require("node-sass/package.json").version).pop();

if (Number(sassVersion) < 4) {
throw new Error(
Expand Down
6 changes: 3 additions & 3 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ describe("sass-loader", () => {
done();
});
});
it("should output a message when `node-sass` is missing", (done) => {
it("should not swallow errors when trying to load node-sass", (done) => {
mockRequire.reRequire(pathToSassLoader);
const module = require("module");
const originalResolve = module._resolveFilename;
Expand All @@ -275,7 +275,7 @@ describe("sass-loader", () => {
if (!filename.match(/node-sass/)) {
return originalResolve.apply(this, arguments);
}
const err = new Error();
const err = new Error("Some error");

err.code = "MODULE_NOT_FOUND";
throw err;
Expand All @@ -285,7 +285,7 @@ describe("sass-loader", () => {
}, (err) => {
module._resolveFilename = originalResolve;
mockRequire.reRequire("node-sass");
err.message.should.match(/Error loading `node-sass`/);
err.message.should.match(/Some error/);
done();
});
});
Expand Down

0 comments on commit 8000575

Please sign in to comment.