From 800057568805645bd2fed58508be50897c5f7e84 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Fri, 1 Jun 2018 19:56:40 +0200 Subject: [PATCH] fix: Errors being swallowed when trying to load node-sass Fixes #563 --- lib/loader.js | 13 ++----------- test/index.test.js | 6 +++--- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index f4158fa5..531196f3 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -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( diff --git a/test/index.test.js b/test/index.test.js index 12f575cd..e7f08561 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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; @@ -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; @@ -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(); }); });