oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.38k stars 2.78k forks source link

Compile error while using pino-pretty #10246

Open ItzRxg3 opened 7 months ago

ItzRxg3 commented 7 months ago

What version of Bun is running?

1.1.3+2615dc742

What platform is your computer?

Microsoft Windows NT 10.0.19045.0 x64

What steps can reproduce the bug?

Sorry for bad english.

  1. Install and import modules pino and pino-pretty (we may skip import pino-pretty, both cases will fail)
  2. Set pino transport to pino-pretty
  3. Compile (bun build app.js --compile --outfile app.exe --target bun)
  4. Run and get crashed

What is the expected behavior?

Logger should work as normally and output text to console

What do you see instead?

5879 | } catch (err) { 5880 | continue; 5881 | } 5882 | } 5883 | if (!fixTarget2) { 5884 | throw new Error(unable to determine transport target for "${origin}"); ^ error: unable to determine transport target for "D:Programmingw-bun1.1.3 ode_modulespinolib\worker.js" at fixTarget (B:/~BUN/root/app.exe:5884:24) at transport (B:/~BUN/root/app.exe:5864:33) at B:/~BUN/root/app.exe:7537:20 at B:/~BUN/root/app.exe:2:47 at B:/~BUN/root/app.exe:7751:30 at B:/~BUN/root/app.exe:2:47 at B:/~BUN/root/app.exe:8048:86 at B:/~BUN/root/app.exe:2:47 at module code (B:/~BUN/root/app.exe:8275:27)

Additional information

No response

ItzRxg3 commented 7 months ago

Code that should fail after build


const pino = require('pino');

module.exports = pino({
    timestamp: pino.stdTimeFunctions.isoTime,
    base: undefined,
    level: 'trace'
}, pino.transport({
    targets: [
        {
            target: 'pino/file',
            level: 'trace',
            options: {
                destination: `${process.cwd()}/latest.log`
            },
        },
        {
            ignore: "time,hostname,pid",
            target: 'pino-pretty',
            level: "debug",
            translateTime: "dd-mm-yyyy, hh:MM:ss TT",
            options: {}
        }
    ],
}));
vktrl commented 3 months ago

It's not a Bun bug, it happens because how Pino works internally with worker threads: https://github.com/pinojs/pino/blob/main/docs/bundling.md

ItzRxg3 commented 3 months ago

nevermind, it's fixed after update of bun (at least latest version)

vktrl commented 3 months ago

nevermind, it's fixed after update of bun (at least latest version)

It only works as long as you run in in the same environment as it was built in. Bun will resolve local paths and they get hardcoded into the bundle. Try bundling a small JS entrypoint with Pino and check the output.

I don't think it's possible to use the bundler plugin to include these files because the JS build API doesn't support --compile option (or maybe it's just undocumented.)

ItzRxg3 commented 3 months ago

oh really i see, bruh