Skip to content

Commit

Permalink
fix: handle pure ESM robustly
Browse files Browse the repository at this point in the history
close #427
  • Loading branch information
JounQin committed Sep 12, 2022
1 parent e3ebd9c commit 085a390
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/eslint-mdx/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ export const loadModule = async <T>(modulePath: string): Promise<T> => {
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-return
return require(modulePath)
} catch (err) {
const code = (err as { code: string }).code
/* istanbul ignore if */
if ((err as { code: string }).code === 'ERR_REQUIRE_ESM') {
if (
code === 'ERR_REQUIRE_ESM' ||
// A pure ESM could have no `exports.require` and then throw the following error,
// related to #427.
code === 'ERR_PACKAGE_PATH_NOT_EXPORTED'
) {
// Load the ESM configuration file using the TypeScript dynamic import workaround.
// Once TypeScript provides support for keeping the dynamic import this workaround can be
// changed to a direct dynamic import.
Expand Down

0 comments on commit 085a390

Please sign in to comment.