question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERROR in bundle.js from UglifyJs: Unexpected token keyword «function»

See original GitHub issue

I continue to get:

ERROR in bundle.js from UglifyJs
Unexpected token keyword «function», expected punc «,» [./src/lock.js:1,0][bundle.js:28150,3119]

Error is the async keyword!? Also, have been struggling trying to get it down in size from 2-4mbs!!! WTF 😦 Why is compiling JS still such a jungle in 2017!?

    key: 'onAuth0Login',
    value: async function onAuth0Login(_ref3) {
      var auth0Token = _ref3.auth0Token,
          profile = _ref3.profile;

$ nmp run prod

npm scripts

    "build": "webpack --progress --colors --optimize-minimize",
    "prod": "BABEL_ENV=production npm run build",

What am I missing?!

.babelrc

{
  "presets": [
    [
      "es2015", {
        "modules": false
      }
    ]
  ],
  "env": {
    "production": {
      "presets": ["babili"]
    }
  },
  "plugins": ["transform-object-rest-spread"]
}

package.json

  "devDependencies": {
    "ava": "^0.19.1",
    "babel-cli": "^6.24.0",
    "babel-core": "^6.24.1",
    "babel-loader": "^7.0.0",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-polyfill": "^6.23.0",
    "babel-preset-babili": "0.0.12",
    "babel-preset-env": "^1.3.1",
    "babel-preset-es2015-native-modules": "^6.9.4",
    "babili": "0.0.12",
    "webpack": "^2.5.1"
  },
  "babel": {
    "presets": [
      "env"
    ],
    "plugins": [
      "transform-object-rest-spread",
      "transform-runtime"
    ]
  },
  "ava": {
     ...
  }

webpack.config.js

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

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [{
      test: /\.js$/,
      exclude: /(node_modules|bower_components)/,
      use: {
        loader: 'babel-loader',
      }
    }]
  },
  stats: {
    colors: true
  },
  devtool: 'source-map'
};

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

33reactions
boopathicommented, May 22, 2017

There are couple of things here -

  1. es2015 preset doesn’t transform async functions. Consider using babel-preset-env. Also, you can use es2017 preset alongside es2015 to convert everything to ES5, but it’s generally better to use babel-preset-env.
  2. Using babili and uglify. I assume you’re bundling/calling webpack as webpack -p as this includes Uglify Plugin as the last step. Also, you’re using Babili in your babelrc. Uglify doesn’t understand ES6 (uglify-es does). Use only one minifier - it’s not necessary to use both babili and Uglify.
  3. Using babili as another preset in babelrc. There are some issues with babili when used along with es2015 preset, consider using babili-webpack-plugin and do NOT run webpack with webpack -p as it includes UglifyJS. More about why to use babili-webpack-plugin is in its own docs.
0reactions
aldrinccommented, Jul 25, 2018

@boopathi Saved me quite a bit of time fussing with Webpack!

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack uglify error: Unexpected token: keyword (function)
I am trying to run npm run build but I can't do this. And I am using webpack 2, But it is giving...
Read more >
How I Fixed: UglifyJs Unexpected token: name (DropIn)
I've been trying – in vain – to build the front end for CodeReviewVideos. The issue I have been hitting upon is as...
Read more >
Unexpected token: punc «)» from qunit helper during a rebuild ...
FYI: I am having a upgrade of discourse currently running, I believe it is stuck as there is no progress anymore and a...
Read more >
JavaScript : UglifyJS throws unexpected token: keyword (const ...
JavaScript : UglifyJS throws unexpected token : keyword (const) with node_modules [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] ...
Read more >
Debugging Story: Build failed, error from Terser - Tan Li Hau
It all started with an error message during the build: 'ERROR in bundle.xxx.js from Terser'.
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