Swiper: Swiper4 seems cannot be compressed by webpack UglifyJs plugin

Created on 15 Sep 2017  Â·  16Comments  Â·  Source: nolimits4web/swiper

Error below occurred when I tried to compress swiper4 via Webpack3 build-in UglifyJs plugin).

ERROR in scripts/lion_6a64ded940eb84148718.js from UglifyJs
Unexpected token: name (i) [scripts/lion_6a64ded940eb84148718.js:6536,6]

Most helpful comment

You are probably including ES-next version of swiper. If you use it with imports you need to use something like babel-loader or import correct version:
import Swiper from 'swiper/dist/js/swiper.js';

All 16 comments

I have same problem.
I use laravel and production crash this error

3.4.2 version is ok Webpack build uglify

You are probably including ES-next version of swiper. If you use it with imports you need to use something like babel-loader or import correct version:
import Swiper from 'swiper/dist/js/swiper.js';

I got the same issue using Swiper 4 and I couldn't figure out how to fix it. Using babel-loader throws this error:

ERROR in bundle.f5a6f788eede24f03ca9.js from UglifyJs
Unexpected token: operator (*) [./node_modules/swiper/dist/js/swiper.esm.bundle.js:1661,85][bundle.f5a6f788eede24f03ca9.js:2631,140]

I was using just import Swiper from 'swiper'; and I can confirm that import Swiper from 'swiper/dist/js/swiper.js'; solved the issue for me.

Yes, adding the absolute-like path fixed the issue :)

@nolimits4web
Didn't help me =(
package.json
"swiper": "=>4.0.2"
js code:
import Swiper from 'swiper/dist/js/swiper.js'
error:
scripts/main_93aa9e33.js from UglifyJs Unexpected token: name (w) [scripts/main_93aa9e33.js:20173,4]

upd:
just add swiper to exclude, but it's not good solution

@Phalconline :
I tried running everything as you did but still getting the same exact error.

Can you tell me what you mean by you added swiper to exclude?

I'm afraid if I can't get this to run I'm going to have use a different slider.

@devanflaherty
yep, on webpack config add next:

module: {
rules: [
{
test: /\.js$/,
exclude: [/(node_modules)(?![/|\\](swiper))/],
use: [
{ loader: 'cache' },
{ loader: 'buble', options: { objectAssign: 'Object.assign' } },
],
}

Saved my butt. Thanks man.

On Nov 4, 2017, 11:58 AM -0600, Alexander Sokolovskiy notifications@github.com, wrote:

@devanflaherty
yep, on webpack config add next:
module: { rules: [ { test: /.js$/, exclude: [/(node_modules|bower_components)(?/|\)/], use: [ { loader: 'cache' }, { loader: 'buble', options: { objectAssign: 'Object.assign' } }, ], }
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@Phalconline Did you resolve this problem, i meet the same problem like you
Unexpected token: name (w) [./node_modules/swiper/dist/js/swiper.esm.bundle.js:15,0]

@ashen9 yep, look below, just exclude swiper exclude: [/(node_modules)(?![/|\\](swiper))/],

It should be exclude: /node_modules\/(?!(dom7|swiper)\/).*/, per the docs.

But this does not solve the issue at all when used with the es2015 preset.

At least template literals are not transpiled by default.

Unexpected character \'\''

Upgrading UglifyJS to version 3 solved it for us.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lxmarinkovic picture lxmarinkovic  Â·  4Comments

chansecampbell picture chansecampbell  Â·  3Comments

QJan84 picture QJan84  Â·  3Comments

Joshanity17 picture Joshanity17  Â·  3Comments

RyanGosden picture RyanGosden  Â·  3Comments