surga surga - 4 months ago 22x
Node.js Question

NpmInstallPlugin - TypeError: undefined is not a function

I'm a super newbie in webpack. I'm starting a new project with babel-loader and react. However, I see this error when starting the server:

this.options = Object.assign(installer.defaultOptions, options);

TypeError: undefined is not a function
at new NpmInstallPlugin (/home/mfebrianto/dev/mfebrianto/food/Menubook/node_modules/npm-install-webpack-plugin/src/plugin.js:32:25)
at Object.<anonymous> (/home/mfebrianto/dev/mfebrianto/food/Menubook/webpack.config.js:79:13)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at module.exports (/usr/lib/node_modules/webpack-dev-server/node_modules/webpack/bin/convert-argv.js:80:13)
at Object.<anonymous> (/usr/lib/node_modules/webpack-dev-server/bin/webpack-dev-server.js:55:48)

This is my webpack.config.js :

const path = require('path');
const merge = require('webpack-merge');
const webpack = require('webpack');
const NpmInstallPlugin = require('npm-install-webpack-plugin');

const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
app: path.join(__dirname, 'app'),
build: path.join(__dirname, 'build')

process.env.BABEL_ENV = TARGET;

const common = {
// Entry accepts a path or an object of entries. We'll be using the
// latter form given it's convenient with more complex configurations.
entry: {
resolve: {
extensions: ['', '.js', '.jsx']
output: {
filename: 'bundle.js'
module: {
loaders: [
// Test expects a RegExp! Note the slashes!
test: /\.css$/,
loaders: ['style', 'css'],
// Include accepts either a path or an array of paths.
// Set up jsx. This accepts js too thanks to RegExp
test: /\.jsx?$/,
// Enable caching for improved performance during development
// It uses default OS directory by default. If you need something
// more custom, pass a path to it. I.e., babel?cacheDirectory=<path>
loaders: ['babel?cacheDirectory'],
// Parse only app files! Without this it will go through entire project.
// In addition to being slow, that will most likely result in an error.

// Default configuration. We will return this if
// Webpack is called outside of npm.
if(TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
devtool: 'eval-source-map',
devServer: {
// Enable history API fallback so HTML5 History API based
// routing works. This is a good default that will come
// in handy in more complicated setups.
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
// Display only errors to reduce the amount of output.
stats: 'errors-only',
// Parse host and port from env so this is easy to customize.
// If you use Vagrant or Cloud9, set
// host: process.env.HOST || '';
// is available to all network devices unlike default
// localhost
host: process.env.HOST,
port: process.env.PORT || 9000
plugins: [
new webpack.HotModuleReplacementPlugin(),
new NpmInstallPlugin({
save: true, // --save
peerDependencies: true

if(TARGET === 'build') {
module.exports = merge(common, {});

What should I do to make the NpmInstallPlugin work in my project?


Make sure that you use node version 4 or above. You can check it with command in console:

node -v

This problem is probably related with not supporting Object.assign() in node version 0.x.