ERROR in bundle.js from UglifyJs: Unexpected token keyword «function»
See original GitHub issueI 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:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There are couple of things here -
es2015
preset doesn’t transformasync functions
. Consider usingbabel-preset-env
. Also, you can usees2017
preset alongsidees2015
to convert everything to ES5, but it’s generally better to usebabel-preset-env
.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.webpack -p
as it includes UglifyJS. More about why to use babili-webpack-plugin is in its own docs.@boopathi Saved me quite a bit of time fussing with Webpack!