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

Programmatic Integration as a transport fails #1735

Closed
altearius opened this issue Jun 16, 2023 · 9 comments
Closed

Programmatic Integration as a transport fails #1735

altearius opened this issue Jun 16, 2023 · 9 comments
Labels

Comments

@altearius
Copy link
Contributor

The Programmatic Integration section currently contains this code example:

const pino = require('pino')
const logger = pino({
  transport: {
    target: 'pino-pretty'
  },
})

logger.info('hi')

The sample currently fails when executed with pino@8.14.1 and pino-pretty@10.0.0 on node 18.16.0:

$ node
Welcome to Node.js v18.16.0.
Type ".help" for more information.
> const pino = require('pino')
undefined
> const logger = pino({
...   transport: {
...     target: 'pino-pretty'
...   },
... })
Uncaught Error: unable to determine transport target for "pino-pretty"
    at fixTarget (/home/...redacted.../node_modules/pino/lib/transport.js:140:13)
    at transport (/home/...redacted.../node_modules/pino/lib/transport.js:114:22)
    at normalizeArgs (/home/...redacted.../node_modules/pino/lib/tools.js:311:16)
    at pino (/home/...redacted.../node_modules/pino/pino.js:87:28)
@mcollina
Copy link
Member

Good spot! It seems it does not work from the node.js REPL. Run it from a script.

@mcollina mcollina transferred this issue from pinojs/pino-pretty Jun 20, 2023
@mcollina
Copy link
Member

Transfered to pino proper because it’s a bug there.

@mcollina mcollina added the bug label Jun 20, 2023
@mcollina
Copy link
Member

A PR to fix this would be very welcomed. Supporting the REPL is low priority.

@nemanjahifolks
Copy link

nemanjahifolks commented Jun 21, 2023

I am experiencing exact same issue with exact same versions, I run it from code, not from REPL. Is there a way around this?

error - Error: unable to determine transport target for "pino-pretty"
    at fixTarget (/home/username/Desktop/folks/node_modules/pino/lib/transport.js:140:13)
    at /home/username/Desktop/folks/node_modules/pino/lib/transport.js:93:17
    at Array.map (<anonymous>)
    at Function.transport (/home/username/Desktop/folks/node_modules/pino/lib/transport.js:90:31)
    at eval (webpack-internal:///(api)/./lib/server/logger/logger.ts:52:60)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  digest: undefined
}

@mcollina
Copy link
Member

mcollina commented Jun 21, 2023

I cannot reproduce it by running as a script. Did you npm i pino-pretty?

@altearius
Copy link
Contributor Author

I investigated this further and found I was able to fix the immediate problem by modifying the for loop in the fixTarget function of the lib/transport.js file in this way:

for (const filePath of callers) {
  try {
    const context = filePath === 'node:repl'
      ? process.cwd() + path.sep
      : filePath

    fixTarget = createRequire(context).resolve(origin)
    break
  } catch (err) {
    // Silent catch
    continue
  }
}

If you think this fix is a good one, I can turn it into a PR. I am not sure how to write a unit test for something like this.

@mcollina
Copy link
Member

Go ahead and send a PR, we'll chat about the unit test there.

@manireddy4u
Copy link

Hello community,

I am using latest node 20.5.1, pino 18.5.0 and pinno-pretty 10.2.0. Here is the snippet for logger.

const logger = require('pino')
({
level: 'debug',
transport: {
target: 'pino-pretty'
},
})

When I am running the package executable which is .exe(created by nexe) I am getting below exception when I run on local the logger works fine. Looking for suggestions. TIA.

Error stack trace:
C:\xxx\LAppMockServer\node_modules\pino\lib\tools.js:311
stream = transport({ caller, ...opts.transport, levels: customLevels })
^^^

SyntaxError: Unexpected token ...
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object. (C:\xxx\LAppMockServer\node_modules\pino\lib\levels.js:11:26)

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants