From 0f880cfb8dfc9b8dad0019d2cde246005c69ef70 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Fri, 22 Oct 2021 22:39:30 +0900 Subject: [PATCH] Better error handling for `MODULE_NOT_FOUND` See --- lib/getPostcssResult.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/getPostcssResult.js b/lib/getPostcssResult.js index 599fd2658c..45090ab344 100644 --- a/lib/getPostcssResult.js +++ b/lib/getPostcssResult.js @@ -93,10 +93,15 @@ function getCustomSyntax(customSyntax) { if (typeof customSyntax === 'string') { try { resolved = require(customSyntax); - } catch { - throw new Error( - `Cannot resolve custom syntax module "${customSyntax}". Check that module "${customSyntax}" is available and spelled correctly.`, - ); + } catch (error) { + // @ts-expect-error -- TS2571: Object is of type 'unknown'. + if (error && error.code === 'MODULE_NOT_FOUND') { + throw new Error( + `Cannot resolve custom syntax module "${customSyntax}". Check that module "${customSyntax}" is available and spelled correctly.`, + ); + } + + throw error; } /*