Trying to build production assets: Unexpected token: name (w)

Running yarn build works fine, but running yarn build:production results in the following:

 ERROR  Failed to compile with 1 errors                                                                                                         


scripts/main_29a38c72.js from UglifyJs
Unexpected token: name (w) [scripts/main_29a38c72.js:6671,4]

error Command failed with exit code 2.

I went through my js and think maybe its from using Swiper (… but I need to use that module and am trying to figure out how to debug this in a more meaningful way. Anyone have any suggestions? As of now I have to deploy this site with a normal build :confused:

I’m wondering if I can build my production assets but maybe just disable Uglify for now… but I don’t know how to do that. Can anyone help with that at least?


Does your theme have this commit?

Can you provide the steps/changes you made to the JS in order for us to help reproduce?

The theme does have that commit.

I think Swiper must be doing something not allowed? Cause even trying to create an instance makes the build blow up. Or maybe its the eslint ignore rule cause it thinks I am defining a var I’m not using? Not sure.

I kind of feel like this is an uglify issue and not a webpack issue, since normal build works fine (that and the fact that the error clearly mentions UglifyJs). I want to try to change some UglifyJs options but can not figure out how to do so.

Here’s a minimal example:

yarn add swiper -d

the most minimal failure case is this main.js

import Swiper from 'swiper';

export default {
  finalize() {
    const swiper = new Swiper('.swiper-container');

@threehz @ben
Hi. I have the same problem, do you found solution for that ?

if I had next code in js file:

import Swiper from 'swiper’
and run
yarn run build:production

scripts/main_cf1d495e.js from UglifyJs Unexpected token: name (w) [scripts/main_cf1d495e.js:875,4]

Possible solution:

I use next
{ test: /\.js$/, exclude: [/(node_modules|bower_components)(?![/|\\](bootstrap|foundation-sites|dom7|swiper))/], use: [ { loader: 'cache' }, { loader: 'buble', options: { objectAssign: 'Object.assign' } }, ], },