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

Loader is run twice if requireModule is called from CJS dependency #231

Open
thecopy opened this issue Oct 14, 2024 · 1 comment
Open

Loader is run twice if requireModule is called from CJS dependency #231

thecopy opened this issue Oct 14, 2024 · 1 comment

Comments

@thecopy
Copy link

thecopy commented Oct 14, 2024

Hello,

My loader file is executed twice and it seems it is caused by a CJS dependency which calls createRequire. Importing createRequire in my ESM script does not execute loader script twice.

Is this expected?

Repro:
loader.mjs

console.log('loaded')

index.mjs

import { pino } from 'pino';
const logger = pino({ transport: { target: 'pino-pretty' }});
logger.info("hello")

Execute:

$ npm i pino pino-pretty
$ node --import=./loader.mjs index.mjs
loaded
loaded
[10:59:13.501] INFO (23004): hello

If i remove { transport: { target: 'pino-pretty' }}:

node --import=./loader.mjs index.mjs
loaded
{"level":30,"time":1728896437188,"pid":23035,"hostname":"Eriks-MacBook-Pro.local","msg":"hello"}

Node v20.18.0
Pino createRequire call: https://github.com/pinojs/pino/blob/main/lib/transport.js#L150

@jsumners-nr
Copy link

You are starting a worker thread by way of the Pino transport. Each thread will execute the loader.

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

2 participants