rollup-plugin-npm-run
raw JSON → 1.0.2 verified Mon Apr 27 auth: no javascript
A Rollup plugin that runs an npm run script after the bundle is written, typically used to restart a dev server or trigger post-build actions. Current version: 1.0.2, stable, low update frequency. Differentiator: simple, lightweight, leverages npm scripts rather than full process managers. Commonly used in development workflows with watch mode.
Common errors
error TypeError: npmRun is not a function ↓
cause Default import used as named import.
fix
Use
import npmRun from 'rollup-plugin-npm-run' instead of import { npmRun } from ... error npmRun: script "start" not found ↓
cause The npm script name does not exist in package.json.
fix
Add a "start" script to your package.json or use an existing script name.
error Error: spawn npm ENOENT ↓
cause Node.js cannot find the npm executable; often due to missing PATH or npm not installed.
fix
Ensure npm is installed and available in PATH. Alternatively, use absolute path to npm.
Warnings
gotcha The plugin runs synchronously on writeBundle, which may cause issues if the script is long-running or starts a server that needs to outlive the Rollup process. ↓
fix Consider using `npm-run-all` or `concurrently` for background processes.
gotcha The script is executed using `spawn` without `shell: true`, so command chaining (&&, ||) may not work. ↓
fix Use `options.args` for flags; to chain commands, create an npm script that chains.
gotcha Does not handle error codes from the spawned process; if the script fails, the error may be silent. ↓
fix Add error handling by listening to the `error` event on the child process (not provided by plugin).
Install
npm install rollup-plugin-npm-run yarn add rollup-plugin-npm-run pnpm add rollup-plugin-npm-run Imports
- default (npmRun) wrong
const { npmRun } = require('rollup-plugin-npm-run')correctimport npmRun from 'rollup-plugin-npm-run' - default (npmRun) with options wrong
import npmRun from 'rollup-plugin-npm-run' npmRun('start', ['--env', 'dev'])correctimport npmRun from 'rollup-plugin-npm-run' npmRun('start', { args: ['--env', 'dev'] })
Quickstart
import npmRun from 'rollup-plugin-npm-run'
export default {
input: 'src/main.js',
output: { dir: 'dist', format: 'esm' },
plugins: [
npmRun('start')
]
}