npm-install-webpack-plugin
raw JSON → 4.0.5 verified Sat Apr 25 auth: no javascript maintenance
Webpack plugin that automatically installs and saves missing npm dependencies during development. Current stable version is 4.0.5 (last released August 2017). It intercepts import/require calls in webpack builds and runs npm install for any missing modules, supporting both ES5 and ES6, CSS imports, namespaced packages, webpack loaders, and .babelrc plugins/presets. Unlike manual npm install workflows, this plugin aims to eliminate the cycle of stopping a dev server to install dependencies. However, it only supports npm (not yarn), relies on webpack 1–3, and is no longer actively maintained.
Common errors
error Error: Cannot find module 'npm-install-webpack-plugin' ↓
cause Plugin not installed in devDependencies.
fix
npm install --save-dev npm-install-webpack-plugin
error TypeError: NpmInstallPlugin is not a constructor ↓
cause Wrong import style: using named import instead of default import.
fix
Use
const NpmInstallPlugin = require('npm-install-webpack-plugin') or import NpmInstallPlugin from 'npm-install-webpack-plugin' error npm-install-webpack-plugin: You must use webpack >= 1.12.0 ↓
cause Webpack version too old (<1.12).
fix
Upgrade webpack to at least 1.12.0 or use an older version of the plugin.
Warnings
deprecated Package is no longer actively maintained. Last release 2017, webpack 4+ not supported. ↓
fix Consider alternatives like webpack-merge-and-include-globally or manual npm install workflows.
breaking Only supports webpack 1–3. Using webpack 4 or 5 will cause errors. ↓
fix Downgrade webpack or use a different plugin.
gotcha npm client only – does not support yarn or pnpm. The `npm` option expects a string like 'tnpm' but not 'yarn'. ↓
fix Use npm or a wrapper that emulates npm CLI.
gotcha May corrupt node_modules if npm install fails mid-flight – no rollback. ↓
fix Lock dependency versions or use a version control system to restore node_modules.
breaking Changes to `dev` option signature in v4: it now accepts a function or boolean, not a string. ↓
fix Update config: new NpmInstallPlugin({ dev: false }) or a function.
Install
npm install npm-install-webpack-plugin yarn add npm-install-webpack-plugin pnpm add npm-install-webpack-plugin Imports
- default wrong
const NpmInstallPlugin = require('npm-install-webpack-plugin')correctimport NpmInstallPlugin from 'npm-install-webpack-plugin' - NpmInstallPlugin wrong
import { NpmInstallPlugin } from 'npm-install-webpack-plugin'correctconst NpmInstallPlugin = require('npm-install-webpack-plugin') - NpmInstallPlugin wrong
plugins: [new require('npm-install-webpack-plugin')()]correctplugins: [new NpmInstallPlugin()]
Quickstart
// webpack.config.js
const NpmInstallPlugin = require('npm-install-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: { filename: 'bundle.js' },
plugins: [
new NpmInstallPlugin({
dev: false,
peerDependencies: true,
quiet: false,
npm: 'npm'
})
]
};