2016-06-19 23 views
0

私はwebpackの超初心者です。私はバベルローダーで新しいプロジェクトを開始し、反応します。ただし、サーバを起動するとき、私はこのエラーを参照してください。NpmInstallPlugin - TypeError:未定義は関数ではありません

/home/mfebrianto/dev/mfebrianto/food/Menubook/node_modules/npm-install-webpack-plugin/src/plugin.js:32 
    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) 

これは私の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: { 
     app: PATHS.app 
    }, 
    resolve: { 
     extensions: ['', '.js', '.jsx'] 
    }, 
    output: { 
     path: PATHS.build, 
     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. 
       include: PATHS.app 
      }, 
      // 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. 
       include: PATHS.app 
      } 
     ] 
    } 
}; 

// 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: { 
      contentBase: PATHS.build, 
      // 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 || '0.0.0.0'; 
      // 
      // 0.0.0.0 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, {}); 
} 

は、私は私のプロジェクトでNpmInstallPluginの仕事をするために何をすべき?

答えて

0

ノードバージョン4以上を使用していることを確認してください。 コンソールでコマンドでそれを確認することができます。

node -v 

この問題は、おそらくnot supporting Object.assign() in node version 0.xと関連しています。

+0

すごいです。できます。ありがとうございました。 – surga

+0

@surga **このプラグインが動作すると、npm-install-webpack-plugin **にノードのバージョンが指定されています:https://github.com/ericclemmons/npm-install-webpack-plugin/blob/master/package。 json#L6-L8 – Everettss

+0

ヒント@ありがとうございます。 – surga

関連する問題