Skip to content

Commit

Permalink
Better error handling for MODULE_NOT_FOUND
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Oct 22, 2021
1 parent 482dcb1 commit 0f880cf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/getPostcssResult.js
Expand Up @@ -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;
}

/*
Expand Down

0 comments on commit 0f880cf

Please sign in to comment.