Open reconbot opened 3 years ago
I would say that's only for commonjs for now. It might be possible to do this with a module loader.
Does this not work?:
const pinoDebug = await import('pino-debug')
@jsumners: const pinoDebug = (await import('pino-debug')).default
works. The issue I'm seeing is with the conditional loading. In the event where NODE_ENV
isn't development
, an error is thrown that debug
is called before pino-debug
. If we use an async import
we get pretty-printed (unredirected output) from avvio
when using Fastify (but no throw). I'm not seeing a way to get the correct behavior I've had in the past with require
and commonjs projects with ESM/Typescript.
I'm using
esbuild
on a project andpino-debug
doesn't work because we're not using common js. I'm sure the exact same problem exists with webpack and maybe something similar with es modules in nodejs itself.pino-debug
modifies the module wrap which is super neat. However it's not used when bundling up the code base because the native require is never called. And it's possibly not used when using a es modules as there seems to be another way to do this kind of thing.I'm pretty sure we could replace the
debug
package with a package of our choosing in the bundler approach. (I'm fuzzy on how.) I don't know what to do with native es modules.Would solving this problem in this repo be welcome? I'd love to use
pino-debug
but if it's only for common js that's ok too.