简体   繁体   English

从npm-install-webpack-plugin运行webpack得到错误

[英]Run webpack got error from npm-install-webpack-plugin

I am using webpack to manage a react+redux web application. 我正在使用webpack来管理react + redux Web应用程序。 When I run webpack command, I got below error: 当我运行webpack命令时,出现以下错误:

node_modules/npm-install-webpack-plugin/src/installer.js:82
  var options = Object.assign({
                       ^
TypeError: Object function Object() { [native code] } has no method 'assign'
    at Object.checkBabel (/var/lib/jenkins/jobs/Go2nurse Web Build/workspace/app/src/main/webres/node_modules/npm-install-webpack-plugin/src/installer.js:82:24)
    at new NpmInstallPlugin (/var/lib/jenkins/jobs/Go2nurse Web Build/workspace/app/src/main/webres/node_modules/npm-install-webpack-plugin/src/plugin.js:36:13)
    at Object.<anonymous> (/var/lib/jenkins/jobs/Go2nurse Web Build/workspace/app/src/main/webres/webpack.config.dev.js:93:5)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/var/lib/jenkins/jobs/Go2nurse Web Build/workspace/app/src/main/webres/webpack.config.js:9:20)

below is my webpack config file: 以下是我的webpack配置文件:

const webpack = require('webpack');
const path = require('path');
const NpmInstallPlugin = require('npm-install-webpack-plugin');
const WebpackShellPlugin = require('webpack-shell-plugin');
var CompressionPlugin = require("compression-webpack-plugin");

const PATHS = {
  react: path.join(__dirname, 'node_modules', 'react', 'dist', 'react.min.js'),
  app: path.join(__dirname, 'src'),
  build: path.join(__dirname, './dist')
};

module.exports = {
  entry: {
    app: './app/index.jsx',
    android: './app/utils/platform_android.js',
    ios: './app/utils/platform_ios.js',
    web: './app/utils/platform_web.js',
    vendor: [
      'axios',
      'react',
      'react-dom',
      'react-redux',
      'react-router',
      'react-router-redux',
      'redux',
      'redux-thunk',
      'react-alert',
      'sha1',
      'moment',
      'nuka-carousel',
      'react-cookie',
      'material-ui',
      'react-spinkit',
      'react-tap-event-plugin',
      'react-tappable',
      'history',
    ],
  },
  output: {
    path: PATHS.build,
    filename: '[name].bundle.js',
  },
  watch: true,
  devtool: 'source-map',
  relativeUrls: true,
  resolve: {
    extensions: ['', '.js', '.jsx', '.css', '.less'],
    modulesDirectories: ['node_modules'],
    alias: {
      normalize_css: __dirname + '/node_modules/normalize.css/normalize.css',
    }
  },
  module: {
    preLoaders: [

      {
        test: /\.js$/,
        loader: "source-map-loader"
      },
    ],
    loaders: [

      {
        test: /\.html$/,
        loader: 'file?name=[name].[ext]',
      },
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader?presets=es2015',
      },
      {
        test: /\.less$/,
        loader: "style!css!less",
      },
      {test: /\.css$/, loader: 'style-loader!css-loader'},
      {test: /\.png$/, loader: "url-loader?limit=100000"},
      // {test: /\.(jpe?g|png|gif|svg)$/i, loader: "file-loader?name=/public/icons/[path]/[name].[ext]"},
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loaders: ['babel-loader?presets=es2015']
      },
      {
        test: /\.svg$/,
        loader: 'svg-sprite',
        include: /public\/icons/
      }
    ]
  },
  plugins: [
    new NpmInstallPlugin({
      save: true // --save
    }),
    new webpack.DefinePlugin({
      "process.env": {
        NODE_ENV: JSON.stringify("development")
      }
    }),
    new WebpackShellPlugin({
      onBuildStart: ['echo "Webpack Start"'],
      onBuildEnd: ['cp ./dist/*.js ../assets/dist/',
        'rm -r dist/web',
        'mkdir -p dist/web/dist',
        'cp ./dist/*.js ./dist/web/dist/',
        'cp ./index.html ./dist/web/']
    }),
    new webpack.optimize.CommonsChunkPlugin(/* chunkName= */["vendor"], /* filename= */"[name].bundle.js", Infinity),
  ],
  devServer: {
    colors: true,
    contentBase: __dirname,
    historyApiFallback: true,
    hot: true,
    inline: true,
    port: 9093,
    progress: true,
    stats: {
      cached: false
    }
  }
}

I don't understand what wrong with my configuration. 我不了解我的配置有什么问题。 Why does webpack complain Object.assign() function. 为什么webpack抱怨Object.assign()函数。 Does it have anything to do with the version? 它与版本有关吗?

Object.assign is a method on es2015 version, you most likely don't have the latest version of node.js. Object.assign是es2015版本上的一种方法,您很可能没有最新版本的node.js。 Try upgrading node.js to the latest version 尝试将node.js升级到最新版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM