Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

javascript - Why is webpack looking for jQuery when the module doesn't require it?

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; }())))) 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...