Skip to content

Commit 7c16afd

Browse files
committed
Try not to use require for modules due to breaking change in Node 22.12: https://github.com/nodejs/node/releases/tag/v22.12.0.
1 parent b3d64f0 commit 7c16afd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

markdownlint-cli2.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,18 @@ const importOrRequireResolve = async (dirOrDirs, id, noRequire) => {
9797
const dirs = Array.isArray(dirOrDirs) ? dirOrDirs : [ dirOrDirs ];
9898
const expandId = expandTildePath(id);
9999
const errors = [];
100+
// Try to load via require(...)
100101
try {
101-
return resolveAndRequire(dynamicRequire, expandId, dirs);
102+
const isModule = /\.mjs$/iu.test(expandId);
103+
if (!isModule) {
104+
// Try not to use require for modules due to breaking change in Node 22.12:
105+
// https://github.com/nodejs/node/releases/tag/v22.12.0
106+
return resolveAndRequire(dynamicRequire, expandId, dirs);
107+
}
102108
} catch (error) {
103109
errors.push(error);
104110
}
111+
// Try to load via import(...)
105112
try {
106113
// eslint-disable-next-line n/no-unsupported-features/node-builtins
107114
const isURL = !pathDefault.isAbsolute(expandId) && URL.canParse(expandId);
@@ -114,6 +121,7 @@ const importOrRequireResolve = async (dirOrDirs, id, noRequire) => {
114121
} catch (error) {
115122
errors.push(error);
116123
}
124+
// Give up
117125
throw new AggregateError(
118126
errors,
119127
`Unable to require or import module '${id}'.`

0 commit comments

Comments
 (0)