Skip to content

Commit ff52be2

Browse files
authored
fix: handle pure ESM robustly (#428)
close #427
1 parent bebc564 commit ff52be2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/proud-trainers-sort.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-mdx": patch
3+
---
4+
5+
fix: handle pure ESM robustly

packages/eslint-mdx/src/helpers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,14 @@ export const loadModule = async <T>(modulePath: string): Promise<T> => {
9090
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-return
9191
return require(modulePath)
9292
} catch (err) {
93+
const code = (err as { code: string }).code
9394
/* istanbul ignore if */
94-
if ((err as { code: string }).code === 'ERR_REQUIRE_ESM') {
95+
if (
96+
code === 'ERR_REQUIRE_ESM' ||
97+
// A pure ESM could have no `exports.require` and then throw the following error,
98+
// related to #427.
99+
code === 'ERR_PACKAGE_PATH_NOT_EXPORTED'
100+
) {
95101
// Load the ESM configuration file using the TypeScript dynamic import workaround.
96102
// Once TypeScript provides support for keeping the dynamic import this workaround can be
97103
// changed to a direct dynamic import.

0 commit comments

Comments
 (0)