12

In my project, I want to import Bootstrap, but it depends on jQuery.

require('jquery/dist/jquery.min'); 
require('bootstrap/dist/js/bootstrap.min');

When I use Webpack to handle this project, it causes an error:

Uncaught Error: Bootstrap's JavaScript requires jQuery

How can I specify jQuery for Bootstrap?

2 Answers 2

21

Replace your require statement with the following:

window.jQuery = window.$ = require('jquery/dist/jquery.min');

Sign up to request clarification or add additional context in comments.

3 Comments

It doesn't work for me. I've got an error window is not defined. What I did wrong?
please add , interface Window { jQuery: any; $: any; } in any.d.ts file
another option is expose-loader
5
require('!!script!jquery/dist/jquery.min.js');

The !!script! is a special flag that will inline the script without using any loaders, equivalent to using a <script> tag in HTML.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.