Skip to content

Commit

Permalink
fix: load CJS appenders for ESM packages
Browse files Browse the repository at this point in the history
  • Loading branch information
lamweili committed Jul 3, 2022
1 parent 3582a00 commit a3fad03
Showing 1 changed file 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

0 comments on commit a3fad03

Please sign in to comment.