rollup-plugin-onerror

raw JSON →
1.0.0 verified Mon Apr 27 auth: no javascript

A Rollup plugin that runs a user-defined callback when the build encounters an error. Version 1.0.0 is the initial and only release. This is a minimal utility package with no dependencies. It differs from Rollup's built-in error handling by allowing custom side effects (e.g., logging, notifications) without altering the build's failure behavior.

error TypeError: onError is not a function
cause Using named import instead of default import in ESM.
fix
Change to 'import onError from 'rollup-plugin-onerror''
error Error: The hook 'onError' is not supported by rollup-plugin-onerror
cause Misunderstanding the plugin as a Rollup hook rather than a regular function.
fix
Use the function directly in the plugins array, not as a hook name.
gotcha Plugin runs callback but does not prevent Rollup from exiting with non-zero code on error.
fix If you need to suppress exit code, use a different plugin or modify process.exitCode within the callback.
gotcha Callback receives the Error object directly; no additional context (e.g., plugin name, file) is provided.
fix Access err.stack for more context. Consider wrapping the error if additional info is needed.
npm install rollup-plugin-onerror
yarn add rollup-plugin-onerror
pnpm add rollup-plugin-onerror

Basic setup: install, import as default, and pass a callback to handle build errors.

// rollup.config.js
import onError from 'rollup-plugin-onerror'

export default {
  input: 'src/index.js',
  output: { file: 'dist/bundle.js', format: 'es' },
  plugins: [
    onError((err) => {
      console.log('Build failed:', err.message)
    })
  ]
}