Pino unable to determine transport target issue
Pino is a logging library that touts high efficiency and very low logging overhead. As with anything, nothing comes free. Pino avoid impacting the main thread by shifting burdensome tasks to node worker, which means more complexity.
One of the resulting complexity is when you need to use Pino for application that use bundler like webpack or esbuild. For example, if you use pino-sentry-transport to send logger error to Sentry for a nextjs application, the nextjs production output will fail to run with with the error Pino unable to determine pino-sentry-transport target
. That is because at runtime, Pino is looking to load the transport package as a standalone js bundle.
In order to address this problem, you should instruct the bundler to output a separate bundle for any transport libraries used with Pino. Pino documentation has a section dedicated to configuring different bundlers like esbuild, webpack for that purpose.
Once that is configured, Pino is now able to load the transport as an independent js bundle at run time and it will stop complaining.