diff --git a/lib/transport-stream.js b/lib/transport-stream.js index bbbf38aab..9da0ff8ce 100644 --- a/lib/transport-stream.js +++ b/lib/transport-stream.js @@ -31,6 +31,9 @@ async function loadTransportStreamBuilder (target) { // See this PR for details: https://github.com/pinojs/thread-stream/pull/34 if ((error.code === 'ENOTDIR' || error.code === 'ERR_MODULE_NOT_FOUND')) { fn = realRequire(target) + } else if (error.code === undefined) { + // When bundled with pkg, an undefined error is thrown when called with realImport + fn = realRequire(decodeURIComponent(target)) } else { throw error } diff --git a/test/transport/bundlers-support.test.js b/test/transport/bundlers-support.test.js index 6fbf1777e..efe8a5edc 100644 --- a/test/transport/bundlers-support.test.js +++ b/test/transport/bundlers-support.test.js @@ -66,6 +66,36 @@ test('pino.transport with worker destination overridden by bundler', async ({ sa globalThis.__bundlerPathsOverrides = undefined }) +test('pino.transport with worker destination overridden by bundler and mjs transport', async ({ same, teardown }) => { + globalThis.__bundlerPathsOverrides = { + 'pino-worker': join(__dirname, '..', '..', 'lib/worker.js') + } + + const destination = file() + const transport = pino.transport({ + targets: [ + { + target: join(__dirname, '..', 'fixtures', 'ts', 'to-file-transport.es2017.cjs'), + options: { destination } + } + ] + }) + teardown(transport.end.bind(transport)) + const instance = pino(transport) + instance.info('hello') + await watchFileCreated(destination) + const result = JSON.parse(await readFile(destination)) + delete result.time + same(result, { + pid, + hostname, + level: 30, + msg: 'hello' + }) + + globalThis.__bundlerPathsOverrides = undefined +}) + test('pino.transport with worker-pipeline destination overridden by bundler', async ({ same, teardown }) => { globalThis.__bundlerPathsOverrides = { 'pino-pipeline-worker': join(__dirname, '..', '..', 'lib/worker-pipeline.js')