webpack Can't resolve 'jquery'

Viewed 24543

Hi I'm a new to Webpack , currently I'm adding this tool to my project, during bundling (webpack ...) jquery-dependent library I get an error like that:

Error: Can't resolve 'jquery' in 'C:\some_folder'

I browsed through similar posts on internet with no positive effect. People recommend using different approaches like : - resolve.alias - plugins ProvidePlugin

I use webpack 3.3.0, in my project jQuery is loaded in normal way via script tag before vendor bundle scripts. Most of vendor librairies including jQuery live not in node_modules folder.

webpack.config.js:

const webpack = require('webpack');
const { resolve } = require('path');

module.exports = env => {
    return {
        context: resolve('src'),
        entry: {
            comp: './start.comp.js',
            culture: './start.culture.js',
            strategy: './start.strategy.js',
            vendors: './start.vendors.js'
        },
        output: {
            path: resolve('dist'),
            publicPath: '/dist/',
            filename: 'bundle.[name].js'
        },
        devtool: env.dev ? 'eval' : 'source-map'
    };
};

the last entry jquery.placeholder.min.js is a problem

require('./../assets/vendor/typeahead.js');
require('./../assets/vendor/hogan-2.0.0.js');
require('./../assets/vendor/swfobject.js');
require('expose-loader?_!./../assets/vendor/underscore-min.js');
require('expose-loader?FastClick!./../assets/vendor/fastclick.js');
require('expose-loader?AOS!./../assets/vendor/aos.js');
require('./../assets/vendor/jquery.placeholder.min.js');
2 Answers

I was working in react i have found that when i import the react-bootstrap components sometimes the components come like {Buttons} from bootstarp; then i got this error. But i solved it by calling the path from bootstrap to react-bootstrap;

Check your auto import call and try changing it. this worked for me.

Related