Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Pino throws 'unable to determine transport target' for pino-pretty

ErrorError: unable to determine transport target for "pino-pretty"

Short answer

Pino loads a transport in a worker thread and looks the target name up with require.resolve. If pino-pretty is not installed where the calling file can see it, or a bundler moved the files, the lookup fails and pino throws this error. Install pino-pretty next to your app, or keep pino and its transports out of the bundle.

  • Applies to pino 9, pino-pretty 13, Node.js 22, Next.js 15
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask Node whether the package can be resolved from your project folder. If this prints a path, the install is fine and the bundler is the likely cause.

    node -e "console.log(require.resolve('pino-pretty'))"
  2. 2Match what you see, then jump to its fix

    1. 1The resolve command in the first step throws MODULE_NOT_FOUND.pino-pretty is not installed in this projectFix
    2. 2The resolve command works, but the error appears only in the built or bundled app (Next.js, webpack, esbuild).A bundler or framework moved pino away from its transportsFix
    3. 3You wrote a path such as ./my-transport.mjs as the target instead of a package name.The target is a relative path that is not valid from the calling fileFix

What does the error look like?

  • Error: unable to determine transport target for "pino-pretty"
  • Cannot find module '.../lib/worker.js'

Cause 1 of 3

pino-pretty is not installed in this project

1Check

Pino resolves the target name from the paths of the files that called it, using require.resolve. A package that is missing from node_modules, is not found. Look for it in your package.json.

npm ls pino-pretty

2Fix

Install it. The pino-pretty project installs it as a development dependency, and recommends against using it in production.

npm install --save-dev pino-pretty

3Verify

Start the app again. Log lines now come out formatted, with no thrown error.

node -e "const pino=require('pino');pino({transport:{target:'pino-pretty'}}).info('hi')"

Confirmed by github.com

Did this fix it?

Cause 2 of 3

A bundler or framework moved pino away from its transports

1Check

Pino starts transports in a worker thread, so the worker file and pino-pretty must exist as real files at runtime. A bundler that inlines pino leaves them out. In Next.js 15 and 16.0 the symptom can also be a Cannot find module error for lib/worker.js.

grep -n "serverExternalPackages" next.config.*

2Fix

In Next.js, list pino as an external package so it is loaded from node_modules (Next.js 16.1 and later does this by default). For other bundlers, mark pino and pino-pretty as external, or follow the pino bundling guide.

// next.config.js
module.exports = {
  serverExternalPackages: ['pino', 'pino-pretty'],
}

3Verify

Rebuild and start the production build, then trigger a log line.

npm run build && npm start

Confirmed by github.com

Did this fix it?

Cause 3 of 3

The target is a relative path that is not valid from the calling file

1Check

A target can be a package name or an absolute or relative file path. A relative path is resolved against the file that created the logger, so moving that file breaks it.

grep -rn "target:" src/

2Fix

Use the package name for pino-pretty. For your own transport file, build an absolute path.

import { join } from 'node:path'
const logger = pino({
  transport: { target: join(import.meta.dirname, 'my-transport.mjs') },
})

3Verify

Start the app and log one line.

node app.js

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Keep pino-pretty in devDependencies and switch the transport off in production, where plain JSON logs are the normal output.
  • After each bundler or framework upgrade, run the production build once and check that a log line prints.
  • Use package names for transports and absolute paths for your own files.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.