mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
Merge pull request #1280 from log4js-node/1277-when-the-type-is-module-there-is-an-error-when-reading-appenders-how-to-deal-with-it
fix: load CJS appenders for ESM packages
This commit is contained in:
commit
d2557dad3e
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user