RunNodeWebpackPlugin

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

Webpack plugin that automatically starts and restarts a Node.js script after webpack compilation. Version 2.0.0 requires webpack ^5.0.0 and ships TypeScript types. Key differentiators: runs scripts only on actual bundle changes (not every recompilation), supports custom script selection, watch-mode control, and process argument configuration. More efficient than nodemon/pm2 for webpack dev workflows. Actively maintained on GitHub.

error TypeError: RunNodeWebpackPlugin is not a constructor
cause Using named import instead of default import in ESM context.
fix
Use default import: import RunNodeWebpackPlugin from 'run-node-webpack-plugin'
error Error: Cannot find module 'webpack'
cause Webpack is not installed or version mismatch (plugin expects webpack 5).
fix
Install webpack 5: npm install webpack@^5.0.0 --save-dev
error The plugin does not restart the script after changes
cause Default 'runOnlyOnChanges' is true but no changes detected in watched scripts, or 'scriptsToWatch' may not include the changed file.
fix
Set 'runOnlyOnChanges' to false or ensure 'scriptsToWatch' includes the correct output filenames.
breaking Version 2.x requires webpack 5; incompatible with webpack 4.
fix Upgrade to webpack 5 or use run-node-webpack-plugin@1.x for webpack 4.
gotcha Default script selection may fail if multiple output files exist and neither 'server.js' nor 'index.js' is among them.
fix Explicitly set the 'scriptToRun' option to the desired output filename or external script path.
gotcha Plugin does not kill child processes gracefully by default; process may remain running if webpack exits abruptly.
fix Use 'processKillSignal' option (e.g., 'SIGTERM') or handle process termination in your script.
gotcha When 'runOnlyOnChanges' is true (default), script restarts only if output files change; watch mode with no file changes will not restart.
fix Set 'runOnlyOnChanges' to false if you need restarts on every recompilation (e.g., when using loaders that affect output but not files).
npm install run-node-webpack-plugin
yarn add run-node-webpack-plugin
pnpm add run-node-webpack-plugin

Basic webpack config for Node.js server that restarts after each compilation using RunNodeWebpackPlugin.

const RunNodeWebpackPlugin = require('run-node-webpack-plugin');
const path = require('path');

module.exports = {
  target: 'node',
  entry: './src/server.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'server.js'
  },
  plugins: [
    new RunNodeWebpackPlugin()
  ]
};