Error: Bootstrap's JavaScript requires jQuery, using Webpack

怎甘沉沦 提交于 2019-11-30 09:22:01
fgonzalez

I finally got rid of the error just by adding a new entry in the ProvidePlugin:

 jQuery:"jquery"

so finally the plugin looks like this:

 new webpack.ProvidePlugin({
  $: "jquery",
  jquery: "jquery",
  "window.jQuery": "jquery",
  jQuery:"jquery"
})

I leave it here in case someone else faces the same problem.

Using Create React App you can import like this:

import 'jquery/src/jquery';
import '../node_modules/bootstrap-sass/assets/javascripts/bootstrap.min';

note: This is for jQuery 3.*

You can also add the Expose Loader package:

npm install expose-loader --save-dev

And use in your webpack entry point (ie. main.js) like this:

import 'expose?$!expose?jQuery!jquery'

// ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!