pino-webpack-plugin

raw JSON →
2.0.0 verified Sat Apr 25 auth: no javascript

A Webpack plugin that enables bundling pino v7+ logger with webpack-generated bundles. Version 2.0.0 supports webpack 5 and requires Node >=12.13.0. It works by extracting pino's worker threads (thread-stream, pino-worker, pino-pipeline-worker, pino-file) into separate bundle files, which must be deployed alongside the main bundle. The plugin allows specifying extra transports like pino-pretty. Key differentiator: it's the official way to use pino in webpack projects, addressing the incompatibility between pino's Node.js Worker Threads architecture and webpack's bundling. Ships TypeScript types.

error Error: Cannot find module 'thread-stream'
cause The worker file thread-stream.js is missing from the output directory or not deployed correctly.
fix
Ensure that the webpack output directory contains all generated files: thread-stream.js, pino-worker.js, pino-pipeline-worker.js, pino-file.js. Include them in deployment.
error TypeError: PinoWebpackPlugin is not a constructor
cause Importing the module incorrectly, e.g., using default import instead of named import.
fix
Use import { PinoWebpackPlugin } from 'pino-webpack-plugin' (ESM) or const { PinoWebpackPlugin } = require('pino-webpack-plugin') (CommonJS).
error Error: The plugin requires a list of transports. Please provide via options.transports
cause The `transports` option is missing in the plugin constructor.
fix
Add transports option array to the constructor, e.g., new PinoWebpackPlugin({ transports: ['pino-pretty'] }).
error Module parse failed: Unexpected token (1:0)
cause Webpack is trying to parse the extra worker files as entry points. This can happen if they are incorrectly included in the build.
fix
Do not import the generated worker files manually. The plugin handles them automatically.
error Error: webpack <5 is not supported
cause Using an older webpack version (4.x or lower).
fix
Upgrade webpack to version 5.61.0 or higher.
gotcha The plugin generates extra bundle files (thread-stream.js, pino-worker.js, pino-pipeline-worker.js, pino-file.js, and any custom transports). These must be deployed alongside the main webpack bundle.
fix Ensure all generated files are included in deployment. Do not assume only the main bundle file is needed.
deprecated The `transports` option is required and must include all used pino transports. Missing a transport will cause runtime errors.
fix Always specify every pino transport used in your code. For example: `transports: ['pino-pretty', 'pino/file']`. Note: `pino/file` is always included automatically.
breaking v2.0.0 dropped support for Node <12.13.0 and webpack <5.61.0. Check your environment compatibility.
fix Upgrade Node to >=12.13.0 and webpack to >=5.61.0.
gotcha The plugin does not support pino v6 or earlier. It is designed for pino v7+ which uses Worker Threads.
fix Ensure pino version is v7 or higher. Check with `npm list pino`.
gotcha Due to pino's architecture, the plugin cannot bundle everything into a single file. The extra worker files are necessary.
fix Accept the multi-file output. Do not attempt to inline or ignore these files.
npm install pino-webpack-plugin
yarn add pino-webpack-plugin
pnpm add pino-webpack-plugin

Basic webpack configuration that includes pino-webpack-plugin with a pino-pretty transport.

const { PinoWebpackPlugin } = require('pino-webpack-plugin');
const path = require('path');

module.exports = {
  mode: 'production',
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  plugins: [
    new PinoWebpackPlugin({
      transports: ['pino-pretty']
    })
  ]
};