Bootstrap: Gulp babel es2015 building Bootstrap 4 – bootstrap/js/src/carousel.js: Unexpected token (219:8)

Created on 15 Feb 2018  Â·  2Comments  Â·  Source: twbs/bootstrap

Hello.

I'm trying to build Bootstrap 4.0.0 with gulp and babel and got an error: bootstrap/js/src/carousel.js: Unexpected token (219:8).

carousel.js:

_getConfig(config) {
  config = {
    ...Default,
    ...config
  }
  Util.typeCheckConfig(NAME, config, DefaultType)
  return config
}

gulpfile.js:

return gulp
  .src(in)
  .pipe(babel({presets: [['es2015']]}))
  .pipe(concat('bootstrap.js'))
  .pipe(gulp.dest(out))

package.json:

"devDependencies": {
  "babel-plugin-transform-es2015-modules-strip": "^0.1.0",
  "babel-preset-es2015": "^6.16.0",
  …
  "gulp-babel": "^7.0.1",
}

Any ideas how to resolve this and build Bootstrap JS?

Most helpful comment

Thanks for advice.

npm install --save-dev babel-preset-env
npm install --save-dev babel-plugin-transform-es2015-modules-strip
npm install --save-dev babel-plugin-proposal-object-rest-spread
return gulp
  .src(in)
  .pipe(babel({
    presets: [['env', {
      loose: true,
      modules: false,
      exclude: ['transform-es2015-typeof-symbol']
    }]],
    plugins: ['transform-es2015-modules-strip', 'transform-object-rest-spread']
  }))
  .pipe(concat('bootstrap.js'))
  .pipe(gulp.dest(out))

After this fixes Bootstrap JS builds fine.

All 2 comments

That's because you need to use Babel 7 + Babel 7 plugins, because you need object spread.
Also, use the same options for Babel as Bootstrap: https://github.com/twbs/bootstrap/blob/v4-dev/.babelrc.js

Thanks for advice.

npm install --save-dev babel-preset-env
npm install --save-dev babel-plugin-transform-es2015-modules-strip
npm install --save-dev babel-plugin-proposal-object-rest-spread
return gulp
  .src(in)
  .pipe(babel({
    presets: [['env', {
      loose: true,
      modules: false,
      exclude: ['transform-es2015-typeof-symbol']
    }]],
    plugins: ['transform-es2015-modules-strip', 'transform-object-rest-spread']
  }))
  .pipe(concat('bootstrap.js'))
  .pipe(gulp.dest(out))

After this fixes Bootstrap JS builds fine.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ziyi2 picture ziyi2  Â·  3Comments

matsava picture matsava  Â·  3Comments

leomao10 picture leomao10  Â·  3Comments

knownasilya picture knownasilya  Â·  3Comments

eddywashere picture eddywashere  Â·  3Comments