Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use with ES Modules #36

Open
reconbot opened this issue Feb 26, 2021 · 3 comments
Open

Use with ES Modules #36

reconbot opened this issue Feb 26, 2021 · 3 comments

Comments

@reconbot
Copy link

I'm using esbuild on a project and pino-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.

@mcollina
Copy link
Member

mcollina commented Feb 26, 2021

I would say that's only for commonjs for now. It might be possible to do this with a module loader.

@jsumners
Copy link
Member

Does this not work?:

const pinoDebug = await import('pino-debug')

@jmealo
Copy link

jmealo commented Sep 7, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants