Unexpected token: punc (:)

See original GitHub issue
  • Operating System: MAC OSX
  • Node Version: v10.13.0
  • NPM Version: 6.6.0
  • webpack Version: 4.39.1
  • terser-webpack-plugin Version: 1.4.1

Expected Behavior

Be able to run npm build without exceptions

Actual Behavior

I dont why but now when im running webpack to build my ReactJS app im getting this error:

ERROR in main.51cb43366055e316f3ed.js from Terser
Unexpected token: punc (:) [main.51cb43366055e316f3ed.js:13127,15]

i can’t find the file main.51cb43366055e316f3ed.js so i don’t know whats the problem. also its important to mention that im not using “terser” directly at all, i don’t know which 3rd module is using it and cause the problem.

Code

// webpack.config.js
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
const ImageminPlugin = require('imagemin-webpack-plugin').default;
const CopyWebpackPlugin = require('copy-webpack-plugin');
import path from 'path';
const useSourceMap = false;

export default {
  resolve: {
    extensions: ['*', '.js', '.jsx', '.json']
  },
  entry: path.resolve(__dirname, 'src/index'),
  target: 'web',
  mode: 'production',
  output: {
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/',
    filename: '[name].[contenthash].js'
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: '[name].[contenthash].css'
    }),

    new HtmlWebpackPlugin({
      template: 'src/index.ejs',
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeRedundantAttributes: true,
        useShortDoctype: true,
        removeEmptyAttributes: true,
        removeStyleLinkTypeAttributes: true,
        keepClosingSlash: true,
        minifyJS: true,
        minifyCSS: true,
        minifyURLs: true
      },
      inject: true,
      trackJSToken: ''
    }),

    new CopyWebpackPlugin([{
       from: 'src/assets',
       to: path.resolve(__dirname, 'dist').concat('/assets')
     }]),

    new ImageminPlugin({pngquant: ({quality: '50'})})
  ],
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: ['babel-loader?cacheDirectory=true']
      },
      {
        test: /\.eot(\?v=\d+.\d+.\d+)?$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              name: '[name].[ext]'
            }
          }
        ]
      },
      {
        test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 10000,
              mimetype: 'application/font-woff',
              name: '[name].[ext]'
            }
          }
        ]
      },
      {
        test: /\.[ot]tf(\?v=\d+.\d+.\d+)?$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 10000,
              mimetype: 'application/octet-stream',
              name: '[name].[ext]'
            }
          }
        ]
      },
      {
        test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 10000,
              mimetype: 'image/svg+xml',
              name: '[name].[ext]'
            }
          }
        ]
      },
      {
        test: /\.(jpe?g|png|gif|ico)$/i,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: '[name].[ext]'
            }
          }
        ]
      },
      {
        test: /(\.css|\.scss|\.sass)$/,
        use: [
          MiniCssExtractPlugin.loader,
          {
            loader: 'css-loader',
            options: {
              sourceMap: useSourceMap
            }
          }, {
            loader: 'postcss-loader',
            options: {
              plugins: () => [
                require('cssnano'),
                require('autoprefixer'),
              ],
              sourceMap: useSourceMap
            }
          }, {
            loader: 'sass-loader',
            options: {
              includePaths: [path.resolve(__dirname, 'src', 'scss')],
              sourceMap: useSourceMap
            }
          }
        ]
      }
    ]
  }
};

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Aug 14, 2019

@thematho we can’t update options because we don’t know what is ecma version you use in code, you need setup this manually

1reaction
alexander-akaitcommented, Aug 7, 2019

Please create minimum reproducible test repo

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uglify SyntaxError: Unexpected token: punc ()) - Stack Overflow
I am trying to use gulp in order to minify a folder containing JS files. However, one of the files has the above...
Read more >
Unexpected token: punc (() - ES6 parsing errors using @babel ...
The error only occurs when running my project in a production environment with UglifyJS enabled. In development, the project run fine.
Read more >
JavaScript : Uglify SyntaxError: Unexpected token: punc ()
JavaScript : Uglify SyntaxError: Unexpected token : punc ()) [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] JavaScript ...
Read more >
Unexpected token: punc(;) - Medium
Recently in my angular application there was a page (component) that was really starting to get quite unresponsive and slow.
Read more >
release throwing Error: SyntaxError: Unexpected token: punc ()
When i try to run ojet serve web --release i am getting Error: SyntaxError: Unexpected token: punc ()). Can you please let me...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found