pinojs / pino

🌲 super fast, all natural json logger
http://getpino.io
MIT License
14.21k stars 875 forks source link

Runtime issue (packed by esbuild): Cannot find module 'pino-pretty' #1164

Closed Unga closed 2 years ago

Unga commented 3 years ago

Hi,

I packed project with esbuild (output is one file index.js). Configuration of Pino transport: transport: { target: 'pino-pretty', options: { colorize: true, ignore: 'time,pid,hostname', }, },

On runtime I receive next error: node:internal/modules/cjs/loader:930 throw err; ^ Error: Cannot find module 'pino-pretty' Require stack: /Users/d/test/index.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:927:15) at Function.resolve (node:internal/modules/cjs/helpers:99:19) at fixTarget (/Users/d/test/index.js:36543:34) at transport (/Users/d/test/index.js:36534:26) at normalizeArgs (/Users/d/test/index.js:41495:20) at Object.pino [as default] (/Users/d/test/index.js:42270:32) ...

Code (row 36543) from my packed index.js: ` function fixTarget(origin) {

if (isAbsolute(origin) || origin.indexOf("file://") === 0) {
  return origin;
}

switch (origin) {
  case "pino/file":
    return join4(__dirname, "..", "file.js");
  default:
    return callerRequire.resolve(origin);   // row 36543
}

}`

Any ideas what to do? Thanks

kibertoad commented 3 years ago

Have you tried adding pino-pretty as a runtime dependency if you are using it?

Unga commented 3 years ago

Have you tried adding pino-pretty as a runtime dependency if you are using it?

Yep. Installed "npm i pino pino-pretty"

It looks like issue is not with dependencies but with import on the fly

kibertoad commented 3 years ago

wonder if bundler is not picking it up due to dynamic import. can you somehow force dependency bundling?

Unga commented 3 years ago

wonder if bundler is not picking it up due to dynamic import. can you somehow force dependency bundling?

Yesterday I switched our project from Winston to Pino because Winston has same issue... I decided to try something new :) But when I added pino-pretty to config I got same issue. What do you mean "force dependency bundling"?

kibertoad commented 3 years ago

Check if esbuild supports manually specifying which dependencies to include.

Unga commented 3 years ago

Check if esbuild supports manually specifying which dependencies to include.

I want to bundle everything to one file. I don't want to setup anything as external dependencies Did not find solution yet :(

github-actions[bot] commented 2 years ago

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.