webpack Module not found: Error: Can't resolve 'jquery'

后端 未结 3 1858
春和景丽
春和景丽 2021-01-04 13:53

When I run the \'webpack\' command, I get this error:

ERROR in ./js/main.js Module not found: Error: Can\'t resolve \'jquery\' in \'...\\js\' @ ./js/main.js 3:0-16 4

相关标签:
3条回答
  • 2021-01-04 14:31

    Well in my case it was something about importing jquery instead of jQuery, it is a webpack config:

    externals: {
        // require("jquery") is external and available
        //  on the global var jQuery
        "jquery": "jQuery"
    }
    

    have a look at this: webpack Can't resolve 'jquery'

    0 讨论(0)
  • 2021-01-04 14:42

    If you are using React with Bootstrap and you're getting this error, it may be because you're using the lower version of Bootstrap. I solved it by upgrading the version to Bootstrap version 5.

    0 讨论(0)
  • 2021-01-04 14:43

    The handlebars has nothing to do with it. The problem is that you changed resolve.modules to [path.join(__dirname, "js/helpers")]. So webpack will only look in js/helpers for any module, but jquery and other dependencies from npm are in node_modules. The default value of resolve.modules is ["node_modules"]. You also need to add node_modules to keep the regular module resolution.

    resolve: {
      modules: [
        path.join(__dirname, "js/helpers"),
        "node_modules"
      ]
    },
    
    0 讨论(0)
提交回复
热议问题