Summary
Because LogLevel
is a const enum, TypeScript when running with isolatedModules
doesn't know the values to inline.
Steps to reproduce
Create a new TS project that has isolatedModules: true
in its tsconfig
and try to import LogLevel
, you'll get a compile error.
And if you try to ts-ignore
the error, then LogLevel.ERROR
ends up being undefined.ERROR
at runtime, b/c the import doesn't work (because the LogLevel
symbol doesn't actually exist at runtime), and undefined.ERROR
will cause an exception.
Possible Solution
For now we're just hard-coding the LogLevel
values, i.e.:
// Use pino for JSON logging
// https://github.com/graphile/logger#creating-a-custom-logger
logger: new GraphileLogger((scope) => {
const scopedLogger = logger.child(scope);
return (level, message, meta = {}) => {
switch (level) {
case "error":
return scopedLogger.error(meta, message);
case "warning":
return scopedLogger.warn(meta, message);
case "debug":
return scopedLogger.debug(meta, message);
case "info":
default:
return scopedLogger.info(meta, message);
}
};
De-const
-izing LogLevel
would fix the issue.