gatsby: WebpackError: Cannot set property 'emulateTransitionEnd' of undefined

Description

I’m getting the following error while trying to import bootstrap library into my Layout. Interesting is that this error doesn’t happen when running the develop version. It only happens when I try to build a production version.

Steps to reproduce

  • Setup a new basic gatsbyjs project
  • Run yarn add bootstrap jquery popper.js to add the dependencies
  • Add a new line import 'bootstrap' into src/layouts/index.js
  • Run yarn build

Expected result

By doing the above steps, it’s expected to have a production-ready version of this website including bootstrap JS libraries.

Actual result

success delete html and css files from previous builds — 0.042 s
success open and validate gatsby-config — 0.178 s
success copy gatsby files — 0.015 s
success onPreBootstrap — 0.026 s
success source and transform nodes — 0.033 s
success building schema — 0.120 s
success createLayouts — 0.012 s
success createPages — 0.000 s
success createPagesStatefully — 0.010 s
success onPreExtractQueries — 0.000 s
success update schema — 0.084 s
success extract queries from components — 0.036 s
success run graphql queries — 0.024 s
success write out page data — 0.004 s
success write out redirect data — 0.001 s
success onPostBootstrap — 0.001 s

info bootstrap finished - 1.594 s

success Building CSS — 3.833 s
success Building production JavaScript bundles — 6.515 s

error Building static HTML for pages failed

See our docs page on debugging HTML builds for help https://goo.gl/yL9lND

  120 |
  121 |     function setTransitionEndSupport() {
> 122 |       $$$1.fn.emulateTransitionEnd = transitionEndEmulator;
      | ^
  123 |       $$$1.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent();
  124 |     }
  125 |     /**


  WebpackError: Cannot set property 'emulateTransitionEnd' of undefined

  - bootstrap.js:122 setTransitionEndSupport
    ~/bootstrap/dist/js/bootstrap.js:122:1

  - bootstrap.js:200
    ~/bootstrap/dist/js/bootstrap.js:200:1

  - bootstrap.js:202
    ~/bootstrap/dist/js/bootstrap.js:202:4

  - bootstrap.js:7
    ~/bootstrap/dist/js/bootstrap.js:7:1

  - bootstrap.js:10 Object.<anonymous>
    ~/bootstrap/dist/js/bootstrap.js:10:2

  - index.js:6 Object.<anonymous>
    src/layouts/index.js:6:1

  - index.js:3 Object.exports.__esModule
    .cache/layouts/index.js:3:3


error Command failed with exit code 1.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 22 (3 by maintainers)

Commits related to this issue

Most upvoted comments

We recommend using react-bootstrap with Gatsby not bootstrap directly. There docs are built with Gatsby actually 😃

https://react-bootstrap.github.io

Using 3rd party libraries to resolve a simple thing brings another level of unnecessary complexity.

Any ideas how to make this work without 3rd party libs?

This works for me with Bootstrap 4 and bootstrap-table:

const webpack = require('webpack');

exports.onCreateWebpackConfig = ({ actions, stage, loaders }) => {
  const config = {
    plugins: [
      new webpack.ProvidePlugin({
        jQuery: 'jquery',
        $: 'jquery',
        jquery: 'jquery',
      }),
    ],
  };
  if (stage === 'build-html') {
    config.module = {
      rules: [
        {
          test: require.resolve('bootstrap'),
          use: loaders.null(),
        },
        {
          test: require.resolve('bootstrap-table'),
          use: loaders.null(),
        },
        {
          test: require.resolve('bootstrap-table/dist/extensions/mobile/bootstrap-table-mobile'),
          use: loaders.null(),
        },
        {
          test: require.resolve('bootstrap-table/dist/extensions/sticky-header/bootstrap-table-sticky-header'),
          use: loaders.null(),
        },
        {
          test: require.resolve('bootstrap-table/dist/extensions/cookie/bootstrap-table-cookie'),
          use: loaders.null(),
        },
        {
          test: require.resolve('jquery'),
          use: loaders.null(),
        },
      ],
    };
  }
  actions.setWebpackConfig(config);
};

@KyleAMathews I appreciated the idea, however I do note that react-bootstrap still has the following in place in their docs:

React-Bootstrap currently targets Bootstrap v3.

Mind you their github speaks differently.

In any case it would be good to get an understanding as to why Gatsby has the conflict. Has any early investigations been undertaken?

error Building static HTML for pages failed

See our docs page on debugging HTML builds for help https://goo.gl/yL9lND

  120 |
  121 |     function setTransitionEndSupport() {
> 122 |       $$$1.fn.emulateTransitionEnd = transitionEndEmulator;
      | ^
  123 |       $$$1.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent();
  124 |     }
  125 |     /**


  WebpackError: TypeError: Cannot set property 'emulateTransitionEnd' of undefined

  - bootstrap.js:122 setTransitionEndSupport
    [lib]/[bootstrap]/dist/js/bootstrap.js:122:1

  - bootstrap.js:199
    [lib]/[bootstrap]/dist/js/bootstrap.js:199:1

  - bootstrap.js:201
    [lib]/[bootstrap]/dist/js/bootstrap.js:201:4

  - bootstrap.js:7
    [lib]/[bootstrap]/dist/js/bootstrap.js:7:63

  - bootstrap.js:10 Object../node_modules/bootstrap/dist/js/bootstrap.js
    [lib]/[bootstrap]/dist/js/bootstrap.js:10:2

  - bootstrap:19 __webpack_require__
    lib/webpack/bootstrap:19:1


  - bootstrap:19 __webpack_require__
    lib/webpack/bootstrap:19:1


  - bootstrap:19 __webpack_require__
    lib/webpack/bootstrap:19:1

  - sync-requires.js:6 Object../.cache/sync-requires.js
    lib/.cache/sync-requires.js:6:62

  - bootstrap:19 __webpack_require__
    lib/webpack/bootstrap:19:1

  - static-entry.js:9 Module../.cache/static-entry.js
    lib/.cache/static-entry.js:9:22

  - bootstrap:19 __webpack_require__
    lib/webpack/bootstrap:19:1

  - bootstrap:83
    lib/webpack/bootstrap:83:1

@jufemaiz while reading the link you posted, i understand why he took the approach, because if memory serves me right, jquery which is a dependency of boostrap, it works on the client side spectrum and gatsby on the other side, the server side. Also after doing some detective work it seems that the bootstrap js tries to access some client only objects, for instance the window object. And with that instead of having going the extra mile and having issues with dependencies throwing errors, he took the cdn approach, just wait for the build to be processed and avoid touching anything that could damage and/or that could not be processed during gatsby’s build process. And then when the user loads the page the js part of bootstrap is fetched from the cdn server and added and all should be working without any issues. For the css/scss side of things as the gatsby-plugin-sass plugin can take care of things like @pieh mentioned. But for the actual js included with boostrap it would a safer bet to go the route that the starter uses, have it injected afterwards.

@jonniebigodes the starter does not include bootstrap in the traditional webpack supported fashion but rather creates script elements in the DOM.

E.g. https://github.com/jaxx2104/gatsby-starter-bootstrap/issues/4

I came here looking for a solution to the same problem. I actually had the same error in react-static (Another SSG that I’m trialling) and I found that it only occurred when I included bootstrap in the root .js files (App or index). For some reason once I got bootstrap out of there then it was fine. Why I don’t know, I’m pretty new to web development, but maybe there is something in Gatsby at that React app level that’s causing problems.

Having to pull in yet another library is not really going to work for us. We want raw bootstrap.

If I can’t solve it in Gatsby then I’ll have to forget it as an option.