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

假如想象 提交于 2020-01-15 10:06:51

问题


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;
}

来源:https://stackoverflow.com/questions/40410888/webpack-error-error-in-bundle-js-from-uglifyjs-syntaxerror-unexpected-token-na

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!