-1

I'd like to preface this question by saying it is hard for me to understand what exactly is going on in this issue and I apologise if it's not up to Stackoverflow's Q&A standards.

I'm trying to import an NPM module that's then compiled by Webpack on our project. This is the module in question, and this is the file that's giving us problems.

At the end of that file, there is the export code:

if (typeof(module) !== 'undefined')
{
    module.exports = window.Swiper;
}
else if (typeof define === 'function' && define.amd) {
    define([], function () {
        'use strict';
        return window.Swiper;
    });
}

And that's it. Throughout the file there are some references to jQuery but nothing that suggests webpack should include it as a module. Do a search for "jQuery" and see for yourself.

So why is it then when we import the plugin like so:

import Swiper from 'swiper'

We get the following error? enter image description here

No where else in the module's package.json or similar does it describe jQuery as a dependency. I have no idea what's happening. If it's any use, here is the code that seems to throw the error in the compiled bundle:

else if (typeof define === 'function' && define.amd) {
        define([], function () {
            'use strict';
            return window.Swiper;
        });
    }
    //# sourceMappingURL=maps/swiper.js.map

    /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"jquery\""); e.code = 'MODULE_NOT_FOUND'; throw e; }())))) 
styke
  • 2,116
  • 2
  • 23
  • 51
  • It appears that your assumptions regarding how webpack determines dependencies are incorrect... The swiper source code references jQuery, which may or may not be optional, but webpack can not make that determination without help. – le3th4x0rbot Jan 05 '17 at 18:23

1 Answers1

0

I think Swiper itself requires jQuery. Because you are in an AMD/webpack environment, Swiper is trying to "import/require" it and webpack cannot find it.

demongolem
  • 9,474
  • 36
  • 90
  • 105
  • I have used Swiper without jQuery successfully. Swiper is built to be library agnostic and I have used it without jQuery successfully outside of AMD environments – styke Jan 05 '17 at 15:54
  • As you can see in the first error stack, swiper.js on line 5333 is trying to load it. Might be a version thing. – Tim Huijgen Jan 05 '17 at 15:58