pinojs / thread-stream

A streaming way to send data to a Node.js Worker Thread
MIT License
229 stars 23 forks source link

Multiple versions of the same package #105

Closed y-nk closed 1 year ago

y-nk commented 2 years ago

Disclaimer

I'm using pino in the context of a nestjs application and the boilerplate is quite large so i won't have a minimal reproducible case, although...

Error message

Here's the stack-trace at the time of crash of my application:

/Users/julien/Work/[redacted]/node_modules/.pnpm/thread-stream@1.0.0/node_modules/thread-stream/lib/worker.js:61
  destination.on('error', function (err) {
              ^
TypeError: destination.on is not a function
    at start (/Users/julien/Work/[redacted]/node_modules/.pnpm/thread-stream@1.0.0/node_modules/thread-stream/lib/worker.js:61:15)

I was clueless until I decided to add some log to the worker's script and see where it goes. I've added a simple console.log({ filename }) right here:

https://github.com/pinojs/thread-stream/blob/6f6375f24e6d5d43bead9e8746c502cabe98fb4a/lib/worker.js#L60-L62

...which led me to discover this:

{ filename: 'file:///Users/julien/Work/[redacted]/node_modules/.pnpm/pino-pretty@4.7.1/node_modules/pino-pretty/index.js' }

...and it's a bit confusing because my package.json has pino-pretty@9 installed. BUT... some of my dependencies have dependencies on pino-pretty@4.7.1 which seems not compatible with the new thread api.

After a quick check it seems that I have multiple versions of pino-pretty installed, and the wrong one get picked:

/Users/julien/Work/[redacted]/node_modules/.pnpm/pino-pretty@4.7.1/
/Users/julien/Work/[redacted]/node_modules/.pnpm/pino-pretty@9.1.0/

So, i think, there's extra-check which needs to be done at some point to avoid picking the wrong version of a package if there's sadly 2 of them in the node_modules.

mcollina commented 2 years ago

pino-pretty v4.7.1 is pretty old. I would recommend finding out the dependency chain and updating it.

y-nk commented 1 year ago

thanks a lot. i ran into every place and upgraded all. 🙏