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

Workers: undefined is not a constructor (evaluating 'new Worker') #3757

Closed
mikerockett opened this issue Jul 23, 2023 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@mikerockett
Copy link

What version of Bun is running?

0.7.0

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

When using Pino, I am unable to use transports – specifically, pino/file, which spawns a Worker as opposed to using the main thread.

  1. bun add pino
  2. Create logger.ts and populate with the below:
import pino from 'pino'
import * as path from 'path'

const transportConfig = pino.transport({
  targets: [
    {
      level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
      target: 'pino/file',
      options: {
        destination: path.resolve(__dirname, '../logs/main.log'),
        mkdir: true
      }
    }
  ]
})

export const logger = pino(transportConfig)

transportConfig.on('ready', () => process.exit(0))
  1. Try log something in entrypoint.ts (logger.info('here')).

What is the expected behavior?

I expect Pino to be able to create a Worker in order for the pino/file target to function.

What do you see instead?

Error thrown:

47 |   const { filename, workerData } = opts
48 |
49 |   const bundlerOverrides = '__bundlerPathsOverrides' in globalThis ? globalThis.__bundlerPathsOverrides : {}
50 |   const toExecute = bundlerOverrides['thread-stream-worker'] || join(__dirname, 'lib', 'worker.js')
51 |
52 |   const worker = new Worker(toExecute, {
                     ^
TypeError: undefined is not a constructor (evaluating 'new Worker')
      at createWorker (/<path>/node_modules/thread-stream/index.js:52:17)
      at new ThreadStream (/<path>/node_modules/thread-stream/index.js:224:18)
      at buildStream (/<path>/node_modules/pino/lib/transport.js:21:17)
      at transport (/<path>/node_modules/pino/lib/transport.js:114:9)
      at /<path>/lib/logger.ts:5:24

Additional information

I'm not sure if this is something Pino needs to fix, however it appears to be trivial and related to Bun still being in the oven…

@mikerockett mikerockett added the bug Something isn't working label Jul 23, 2023
@Jarred-Sumner
Copy link
Collaborator

Duplicate of #901

@Jarred-Sumner Jarred-Sumner marked this as a duplicate of #901 Jul 24, 2023
@Jarred-Sumner Jarred-Sumner closed this as not planned Won't fix, can't repro, duplicate, stale Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants