pinojs / pino-pretty

🌲Basic prettifier for Pino log lines
MIT License
1.27k stars 150 forks source link

uncaughtException: Cannot find module '...\\server_fastify\\lib\\worker.js' #394

Closed Yberion closed 1 year ago

Yberion commented 1 year ago

Hello,

I wanted to use pino-pretty on my Fastify SSR server on my Angular project, but it seems that it's not finding a module. I think it's related to how Angular compiles the project.

I'm getting this error:

{"date":"Wed Jan 25 2023 22:01:18 GMT+0100 (heure normale d’Europe centrale)","error":{"code":"MODULE_NOT_FOUND","requireStack":[]},"exception":true,"logging.googleapis.com/labels":{},"message":"uncaughtException: Cannot find module 'D:\\GitHub\\brittany-ferries\\dd-front\\dist\\dd\\server_fastify\\lib\\worker.js'\nError: Cannot find module 'D:\\GitHub\\brittany-ferries\\dd-front\\dist\\dd\\server_fastify\\lib\\worker.js'\n    at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)\n    at Module._load (node:internal/modules/cjs/loader:885:27)\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n    at MessagePort.<anonymous> (node:internal/main/worker_thread:159:24)\n    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:735:20)\n    at exports.emitMessage (node:internal/per_context/messageport:23:28)","os":{"loadavg":[0,0,0],"uptime":443240.593},"process":{"argv":["C:\\Logiciels\\nodejs\\node.exe","D:\\GitHub\\brittany-ferries\\dd-front\\dist\\dd\\server_fastify\\main.js"],"cwd":"D:\\GitHub\\brittany-ferries\\dd-front","execPath":"C:\\Logiciels\\nodejs\\node.exe","gid":null,"memoryUsage":{"arrayBuffers":4292172,"external":1066989,"heapTotal":82501632,"heapUsed":59233208,"rss":128172032},"pid":23188,"uid":null,"version":"v18.13.0"},"severity":"ERROR","stack":"Error: Cannot find module 'D:\\GitHub\\brittany-ferries\\dd-front\\dist\\dd\\server_fastify\\lib\\worker.js'\n    at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)\n    at Module._load (node:internal/modules/cjs/loader:885:27)\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n    at MessagePort.<anonymous> (node:internal/main/worker_thread:159:24)\n    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:735:20)\n    at exports.emitMessage (node:internal/per_context/messageport:23:28)","timestamp":"2023-01-25T21:01:18.488Z","trace":[{"column":15,"file":"node:internal/modules/cjs/loader","function":"Module._resolveFilename","line":1039,"method":"_resolveFilename","native":false},{"column":27,"file":"node:internal/modules/cjs/loader","function":"Module._load","line":885,"method":"_load","native":false},{"column":12,"file":"node:internal/modules/run_main","function":"Function.executeUserEntryPoint [as runMain]","line":81,"method":"executeUserEntryPoint [as runMain]","native":false},{"column":24,"file":"node:internal/main/worker_thread","function":null,"line":159,"method":null,"native":false},{"column":20,"file":"node:internal/event_target","function":"[nodejs.internal.kHybridDispatch]","line":735,"method":"kHybridDispatch]","native":false},{"column":28,"file":"node:internal/per_context/messageport","function":"exports.emitMessage","line":23,"method":"emitMessage","native":false}]}

The dist folder looks as follow for a compiled Angular project (dev mode):

image

I'm following the doc from https://www.fastify.io/docs/latest/Reference/Logging/#enable-logging

const fastify = Fastify({
    logger: {
      transport: {
        target: 'pino-pretty',
        options: {
          translateTime: 'HH:MM:ss Z',
          ignore: 'pid,hostname',
        }
      }
    },
    connectionTimeout: options.connectionTimeout
  });

Is there an alternative to format the logs (removing fields, adding new ones)?

NodeJS 18.13.0 Fastify 4.12.0 pino-pretty 9.1.1 Typescript 4.8.4 Angular 14.2.x (not using esbuild)

mcollina commented 1 year ago

Check out https://getpino.io/#/docs/bundling

Yberion commented 1 year ago

Thanks for the answer.

I checked the plugin and how I could integrate that in our Angular project. I think it would add too much "overhead" and maintenance steps.

I will try to configure formatting using formatters, base, etc (without pino-pretty)