abstract-logging
abstract-logging copied to clipboard
Rollup fails to build when importing abstract-logging
Would you like to send a Pull Request to address this issue? Remember to add unit tests.
I encountered this issue as well when I tried to bundle fastify
with rollup
.
Code like:
const logger = require("abstract-logging");
logger.info(111);
works fine. But when we bundle it with rollup
, it will crash with the following error:
logger.info(111);
^
TypeError: logger.info is not a function
The generated bundle will be something like this:
'use strict';
var rollupPlayground = {};
var abstractLoggingExports = {};
var abstractLogging = {
get exports(){ return abstractLoggingExports; },
set exports(v){ abstractLoggingExports = v; },
};
(function (module) {
function noop () { }
const proto = {
fatal: noop,
error: noop,
warn: noop,
info: noop,
debug: noop,
trace: noop
};
Object.defineProperty(module, 'exports', {
get () {
return Object.create(proto)
}
});
} (abstractLogging));
const logger = abstractLoggingExports;
logger.info(111);
module.exports = rollupPlayground;
The abstractLogger.exports
setter isn't triggered by Object.defineProperty()
, which makes abstractLoggingExports
empty and calls to its methods will fail.
Tried some of the rollup
options but without luck.