简体   繁体   中英

webpack error -ERROR in bundle.js from UglifyJs Unexpected token: name (urlParts)

I am starting to learn webpack. I created a simple config file:

const path = require('path');
const webpack = require('webpack');

module.exports = {
  context: __dirname,
  entry: './src/index.js',
  output: {
  filename: 'bundle.js',
  publicPath: '/',
  path: path.resolve(__dirname, 'dist')
},
devtool: 'inline-source-map',
devServer: {
  contentBase: path.join(__dirname, 'dist'),
  hot: true
},
plugins: [new webpack.HotModuleReplacementPlugin()],
module: {
  rules: [
    {
      test: /\.js$/,
      exclude: /node_modules/,
      include: path.join(__dirname, 'src'),
      use: ['babel-loader']
    },
    {
      test: /\.css$/,
      use: ['style-loader', 'css-loader']
    },
    {
      test: /\.(png|svg|jpg|gif)$/,
      use: ['file-loader']
    },
    {
      test: /\.(woff|woff2|eot|ttf|otf)$/,
      use: ['file-loader']
    }
   ] 
 }
};

Then I created src/index.js with a simple console.log('hello').

In package.json I put this: "start": "webpack-dev-server --config webpack.config.local.js -p",

When I run "npm start" in the terminal I get this weird error:

ERROR in bundle.js from UglifyJs Unexpected token: name (urlParts) [(webpack)-dev-server/client?http:/localhost:8080:24,0][bundle.js:4026,4]

The bundle.js looks very weird since I haven't write all this code. I googled but cannot find the solution, do you have any idea what I am doing wrong? Thanks!

Edit: I added this in .babelrc but still same error:

{"presets": ["react", "stage-2", "es2015"]}

Remove the -p from your npm script, this is why is minifying the code. It seems that you are using webpack-dev-server and a config.local file so I assume this is only for local development, in this case the -p from webpack it's not needed.

Regarding the size of bundle.js I see you are excluding the node_modules folder, so it seems ok for me. Try to add a new script in your package.json like this:

"build": ""webpack --config webpack.config.local.js" 

and see the file that will be created, so you can better understand what is going on. Hope this help, cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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