From d5ad7a9c5745d489671c432b9eef47fea569e062 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Thu, 25 May 2023 22:59:03 +0300 Subject: [PATCH] fix: handling error better --- src/index.js | 10 +++++++++- src/utils.js | 11 ++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/index.js b/src/index.js index 3ec5911..fa3c200 100644 --- a/src/index.js +++ b/src/index.js @@ -12,7 +12,15 @@ import LessError from "./LessError"; async function lessLoader(source) { const options = this.getOptions(schema); const callback = this.async(); - const implementation = getLessImplementation(this, options.implementation); + let implementation; + + try { + implementation = getLessImplementation(this, options.implementation); + } catch (error) { + callback(error); + + return; + } if (!implementation) { callback( diff --git a/src/utils.js b/src/utils.js index 184bd44..32c13cd 100644 --- a/src/utils.js +++ b/src/utils.js @@ -232,15 +232,8 @@ function getLessImplementation(loaderContext, implementation) { if (!implementation || typeof implementation === "string") { const lessImplPkg = implementation || "less"; - try { - // eslint-disable-next-line import/no-dynamic-require, global-require - resolvedImplementation = require(lessImplPkg); - } catch (error) { - loaderContext.emitError(error); - - // eslint-disable-next-line consistent-return - return; - } + // eslint-disable-next-line import/no-dynamic-require, global-require + resolvedImplementation = require(lessImplPkg); } // eslint-disable-next-line consistent-return