Skip to content

Commit

Permalink
Merge pull request #1280 from log4js-node/1277-when-the-type-is-modul…
Browse files Browse the repository at this point in the history
…e-there-is-an-error-when-reading-appenders-how-to-deal-with-it

fix: load CJS appenders for ESM packages
  • Loading branch information
lamweili committed Jul 3, 2022
2 parents 3582a00 + 2ff151b commit d2557da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/appenders/index.js
Expand Up @@ -22,10 +22,18 @@ coreAppenders.set('tcp', require('./tcp'));
const appenders = new Map();

const tryLoading = (modulePath, config) => {
debug('Loading module from ', modulePath);
let resolvedPath;
try {
const modulePathCJS = `${modulePath}.cjs`;
resolvedPath = require.resolve(modulePathCJS);
debug('Loading module from ', modulePathCJS);
} catch (e) {
resolvedPath = modulePath;
debug('Loading module from ', modulePath);
}
try {
// eslint-disable-next-line global-require, import/no-dynamic-require
return require(modulePath);
return require(resolvedPath);
} catch (e) {
// if the module was found, and we still got an error, then raise it
configuration.throwExceptionIf(
Expand Down
File renamed without changes.

0 comments on commit d2557da

Please sign in to comment.