Webpack error ERROR in bundle.js from UglifyJs Syn

2019-08-03 03:36发布

问题:

I'm trying to prepare my Express/ReactJS app for production with webpack, and when running NODE_ENV=production webpack -p --config webpack.production.config.js

I get error:

ERROR in bundle.js from UglifyJs SyntaxError: Unexpected token: name (prop) [./~/connect-mongo/src/index.js:10,0]

Here's my webpack.production.config file:

var path = require('path');

var config = {
  entry: path.resolve(__dirname, './server.js'),
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    preLoaders: [
      { test: /\.json$/, loader: 'json'},
    ],
    loaders: [
      { test: /\.js$/, exclude: /node_modules/, loader: 'babel'},
      { test: /\.jsx$/, exclude: /node_modules/, loader: 'babel'},
      { test: /\.es6$/, exclude: /node_modules/, loader: 'babel'}
    ],
  },
  node: {
      fs: 'empty',
      net: 'empty',
      tls: 'empty',
      module: 'empty'
    }
};

module.exports = config;

EDIT:

The error is a result of line 10 in node_modules/connect-mongo/src/index:

'use strict';
/* eslint indent: [error, 4] */

const Promise = require('bluebird');
const MongoClient = require('mongodb');

function defaultSerializeFunction(session) {
    // Copy each property of the session to a new object
    const obj = {};
    let prop;

    for (prop in session) {
        if (prop === 'cookie') {
            // Convert the cookie instance to an object, if possible
            // This gets rid of the duplicate object under session.cookie.data property
            obj.cookie = session.cookie.toJSON ? session.cookie.toJSON() : session.cookie;
        } else {
            obj[prop] = session[prop];
        }
    }

    return obj;
}