Pino throws 'unable to determine transport target' for pino-pretty
Error: 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.
Fix it fast
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'))"2Match what you see, then jump to its fix
- 1
The resolve command in the first step throws MODULE_NOT_FOUND.pino-pretty is not installed in this projectFix - 2
The 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
You 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
- 1
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-pretty2Fix
Install it. The pino-pretty project installs it as a development dependency, and recommends against using it in production.
npm install --save-dev pino-pretty3Verify
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
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 startConfirmed by github.com
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.jsConfirmed by raw.githubusercontent.com
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
Back end
create-next-app keeps creating a TypeScript project
Would you like to use TypeScript? No / Yes
create-next-app now makes a TypeScript project by default.
2 causes, each with a fixBack end
Show a custom sign-in error in NextAuth without leaving the page
http://localhost:3000/api/auth/error?error=...
By default a failed NextAuth credentials sign-in navigates to the error page with the message in the URL.
3 causes, each with a fixBack end
Request body is rejected as too large in Next.js (1 MB default)
413 Payload Too Large
Next.js limits request bodies to 1 MB by default, in both Pages Router API routes and Server Actions.
3 causes, each with a fixBack end
Next.js server code cannot connect to its own API on 127.0.0.1
Error: connect ECONNREFUSED 127.0.0.1:3003
ECONNREFUSED means nothing was listening at that address and port when the server-side fetch ran.
2 causes, each with a fixBack end
next build stops with: Failed to collect page data for a route
Error: Failed to collect page data for /dashboard
Failed to collect page data for a route is the last line of a failed build, not the cause.
3 causes, each with a fixBack end
TypeError: Failed to parse URL when a Next.js server fetches its own API
TypeError: Failed to parse URL from undefined/api/test
Server code has no page address, so fetch('/api/test') cannot be turned into a full URL and throws Failed to parse URL.
3 causes, each with a fix