Uncaught error bootstrap s javascript requires jquery

I'am very new in Bootstrap. So my step by step install bottstrap as written hire https://v4-alpha.getbootstrap.com/getting-started/download/#npm install jquery by npm i jquery write a code impo...

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

Comments

@alexey2baranov

I’am very new in Bootstrap. So my step by step

  1. install bottstrap as written hire https://v4-alpha.getbootstrap.com/getting-started/download/#npm
  2. install jquery by npm i jquery
  3. write a code
import $ from 'jquery'
require('bootstrap')
  1. run it on webpack-dev-server npm run dev
  2. And finally get error

Uncaught Error: Bootstrap’s JavaScript requires jQuery. jQuery must be included before Bootstrap’s JavaScript.
at eval (eval at (app.js:690), :8:9)
at Object. (app.js:690)
at webpack_require (app.js:556)
at fn (app.js:87)
at eval (eval at (app.js:684), :17:1)
at Object. (app.js:684)
at webpack_require (app.js:556)
at fn (app.js:87)
at Object. (app.js:587)
at webpack_require (app.js:556)

@CyrilWork

@alexey2baranov

hmmmm… old scool scripting in 2017 year? doesn’t bootstrap 4 support commonjs or es6 importing?

i suppose if my some module use jquery it will be included in webpack boundle and another version of jquery will be at the end of body tag just for bootstrap works. so i will get double included jquery library on my page. I think there should be another way for including bootstrap into webpacked projects

IamManchanda, luzanovdm, manniL, mkstix6, snboisen, nathan-osman, mazenbesher, eberkund, SamUndefined, dmonti, and 3 more reacted with thumbs up emoji
BillyWM, dongepulango, and dheerajkhowar reacted with thumbs down emoji

@IamManchanda

@DavidStrada

@alexey2baranov Bootstrap in most of it’s plug-ins relay on having $/jQuery available globally so that’s why you get that message, what you could try is making jQuery available globally and avoid this message, I know it’s a dirty hack but until they start including their dependencies I’m afraid is your only option.

e.g.

import $ from "jquery"
window.jQuery = $

@DavidStrada

Also given that you’re using webpack as a work around you could try this.

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

Wepack Docs

@christianirack

Testing with this

import jquery from ‘jquery’
window.jQuery = jquery
require(‘bootstrap’)

@alexey2baranov

@Johann-S

@rolele

@Johann-S The doc is not rendered well. I see all the {% highlight js %} commands.

@wolfy1339

@rolele that’s not the compiled docs. That’s the source.

@anarerdene

Also demo links not working.

@peterbarraud

Hey does anyone else get this error:
Uncaught Error: Bootstrap dropdown require Popper.js
So I do
require('popper');
And get this error:
Cannot find module 'rijs.resdir' from 'C:UsersbarraudDocumentstechbrowserify-prototypingrapo-browserify-part-2-external-cssnode_modulespopperdist'

@Johann-S

Popper.js should be available in the Window scope so you should do :
window.Popper = require('popper')

@peterbarraud

Thanks for the super quick response but it still gives the same error. The includes in my file are as such:

const $ = require('jquery');
window.jQuery = $;
window.Popper = require('popper')
require('bootstrap');

@Johann-S

be sure to use the last release of Popper.js (1.12.5) not the one required by the beta 1 (1.11.0)

@peterbarraud

When I run npm -v popper it shows 4.2.0. What is that supposed to mean?

@Johann-S

Because the package name is popper.js 😉

@peterbarraud

Thanks much @Johann-S . It now works perfect :)

Uncaught error: bootstrap’s javascript requires jquery – introduction

When you utilize Bootstrap and add jQuery 1.x.x to build up your site, have you ever got the Uncaught error: bootstrap’s javascript requires jquery yet? If yes, do you know how to deal with the trouble? In case you are looking for a useful solution for this issue, let’s take a look at the blog. So, today, we would like to bring you some methods that you can try to get the most suitable one.

How to fix the Uncaught error: bootstrap’s javascript requires jquery?

First of all, let’s make sure that you added jQuery before bootstrap since bootstrap use the features of jQuery. For example, if you are in a Browser-Only environment, then the right order you should try is:

<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/wow.min.js"></script>

Besides, in case you are in Node or CommonJS + Browser environment including Electron, Node-Webkit, etc, the main reason that causes the error is that jQuery’s export logic will check the module before the window:

if (typeof module === "object" && typeof module.exports === "object") {
// CommonJS/Node
} else {
// window
}

As it exports itself through the module.exports, both jQuery and $ won’t be assigned to the window. Therefore, you need to change
<script src="path/to/jquery.js"></script>;
into a require statement, such as:

<script>
window.jQuery = window.$ = require('jquery');
</script>

Last but not least, in case your electron app doesn’t need
nodeIntegration
, simply set it to
false
. So, everything is done and you don’t need to use the solution above.

Final thoughts

In conclusion, we hope that some methods we suggested above will be useful for you. Don’t hesitate to try them to solve the trouble quickly. Any idea for this issue? If yes, why don’t you show it to us by leaving your comment below? What’s more? We are providing a lot of high-quality free WordPress Themes, let’s visit our site and get the best one for your site.

  • Author
  • Recent Posts

Lt Digital Team (Content &Amp; Marketing)

Welcome to LT Digital Team, we’re small team with 5 digital content marketers. We make daily blogs for Joomla! and WordPress CMS, support customers and everyone who has issues with these CMSs and solve any issues with blog instruction posts, trusted by over 1.5 million readers worldwide.

Lt Digital Team (Content &Amp; Marketing)

We might face `Uncaught error: bootstrap’s javascript requires jquery ` error while using the Bootstrap framework which tells us that the `jQuery` library is not loaded correctly, and the reason could be the inappropriate order of requesting the files from the Bootstrap and the jQuery files. In this situation, you need to reorder the request lines, so the top request should be for the dependency file which the next requests are depending on to work normally. Keep up till the end as we discuss all the situations that cause this error and how to solve them.

 Table of Contents:

  1. What is Bootstrap?
  2. What is jQuery?
  3. The Solutions
    1. Solution 1: Order the requests files correctly
    2. Solution 2: Use older jQuery and Bootstrap versions to support older browsers
    3. Solution 3: Load jQuery with require.js
  4. The Conclusion


What is Bootstrap? #

Bootstrap is a framework developed by Mark Otto and Jacob Thornton from the Twitter team, then on August 19, 2011, it became an open-source project so every developer in the world is able to contribute to the project.

Bootstrap’s design direction is mobile-first, so we can use it to build responsive, mobile-first sites easily, plus we can use plugins in our sites like date picker, dropdowns, and much more which are built by jQuery.

Bootstrap removed the dependency on jQuery on Bootstrap 5 and moved to vanilla JavaScript.

What is jQuery? #

jQuery is a JavaScript library that gives you the ability to write less code than usual to do things like manipulating the DOM, animation, AJAX, etc.

It’s a free open-source project with a permissive MIT license, and most of the sites on the web are using it.

jQuery also provides cross-browser functionality which makes the site work without problems on a lot of different browsers versions, and that is great if your goal is to cover a big range of browsers so you need to support the legacy browsers.

Bootstrap 4 and below are using the jQuery library to make plugins and widgets for us to use on our sites while developing with Bootstrap.


The Solutions #

Solution 1: Order the requests of files correctly

This is the most basic solution, and it solves the problem if you are requesting the files through CDN ( Content Delivery Network  ) like jsDelivr or others.

Now we need to request the Bootstrap JavaScript file and its dependencies like jQuery and popper, so everything works normally.

It’s preferable to include those script elements before the body element so we know for sure that the DOM is loaded, so we include them in this order: 

<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous"></script>

The jQuery file must come first because the other files depend on it, then the popper file and the last file is the Bootstrap JavaScript file.


Solution 2: Use older jQuery and Bootstrap versions to support older browsers

If you need to support older browsers like Internet Explorer 8, you have to use jQuery’s 1.x version and Bootstrap’s  3.4 version.

So you will need to include the CDNs requests to the jQuery and Bootstrap js files, and preferably to include them before the «body» element like the following:

<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

Solution 3: Load jQuery with require.js

If the above solutions didn’t solve the error, you can use require.js to load jQuery through CDN link.

Require.js is a Javascript file or module loader which improves the speed and quality of the code.

First, you need to download the require.js file from here, then move this file to your script directory which is called in this example «script».

Now make 2 more JavaScript files, one for the require.js config called «app.js» in your «script» directory, and a file for requiring the jQuery logic called «main.js» in your «script» directory.

The «app.js» should have the config for require.js for this example like the following:

requirejs.config({
    "baseUrl": "script",
    "paths": {
      "jquery": "//cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min"
    }
});

requirejs(["main"]); // including main.js

The «main.js» file which is included at the end of the above code should have the logic for requesting jQuery like the following:

define(["jquery"], function($) {
    console.log($); // for testing
});

Finally, we include this script element before any script in our HTML file to load «require.js» first, then load the «app.js» file as the following: 

<script data-main="script/app" src="script/require.js"></script>


The Conclusion

In this article, we introduced the Bootstrap framework and jQuery library, learned what are the solutions to solve «Uncaught error: bootstrap’s javascript requires jquery» error like how to include the CDNs requests in the appropriate order,  we learned also to use older versions of jQuery and Bootstrap to support legacy browsers like Internet Explorer 8, and how to load jQuery with require.js Thanks for reading till the end and I hope you managed to resolve the error.

  • Remove From My Forums
  • Question

  • User-110504647 posted

    Hi all,

    I´ve seen several answers to this error in Netbeans, but I really don´t know how still solve it if you please can help me here,

    i´m just starting my very first course on HTML/CSS that´s why I did not get the solutions maybe,

    Following my course, my code is exactly the same than in the course and all instructions were followed, 

    i have no errors when I check my web page via F12,

    But when I click on:

    bootstrap.min.js

    if(«undefined»==typeof jQuery)throw new Error(«Bootstrap’s JavaScript requires jQuery»)

    jquery.min

    Error(«jQuery requires a window with a document»)

    Please help!

    Thanks a lot

    Rosi

    <script src=»js/jquery.min.js»> type=»text/javascript»></script> <script src=»js/bootstrap.min.js»> type=»text/javascript»></script>

Answers

  • User839733648 posted

    Hi Rosi Q,

    According to your description and code, I’ve tested it and it works well on my side.

    Bootstrap’s JavaScript requires jQuery

    This error occurs always because you’ve not loaded the jquery.min.js before bootstrap.min.js.

    But your code is correct, I’m confused that why you have this error.

    As mgebhard has mentioned, you may check that if the relative root is correct.

    My web page looks ok but when I minimized the page the toolbar is not appearing

    Do you mean that the navbar content miss when minimizing the page?

    This is because you’ve set collapse class to button, you could move it and the button will work well.

    Here is my working code.

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Blog de Rosi</title>
        <link href="Reference/bootstrap.min.css" rel="stylesheet" />
        <script src="Reference/jquery-3.3.1.min.js"></script>
        <script src="Reference/bootstrap.min.js"></script>
    </head>
    <body>
        <nav class="navbar navbar-default navbar-static-top">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
                        <span class="sr-only">Este botón despliega la barra de navegación</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">Mi primer proyecto</a>
                </div>
                <div id="navbar" class="navbar-collapse collapse">
                    <ul class="nav navbar-nav">
                        <li><a href="#">Entradas</a></li>
                        <li><a href="#">Favoritos</a></li>
                    </ul>
                </div>
            </div>
        </nav>
    </body>
    </html>

    Best Regards,

    Jenifer

    • Marked as answer by

      Thursday, October 7, 2021 12:00 AM

SharePoint Online training courses

Recently we were building a SharePoint dashboard page where we were using Bootstrap to show some tab views and also we were showing some accordion views in SharePoint online site.

But we saw a scripting error in the developer tools (Google Chrome).

The error message was like below: Uncaught Error: bootstrap’s javascript requires jquery at bootstrap.min.js

bootstrap’s javascript requires jquery
bootstrap’s javascript requires jquery

Since we were using Bootstrap, we were using the below js file.

<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.1/bootstrap-table.min.js"></script>

But the problem was that jquery files reference was missing in the page. So we gave the jQuery file references like below:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

Sometimes even if both the files are presented, you might also receive the error. That time, both the order of the files is important. Both the files should be presented in the below order.

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.1/bootstrap-table.min.js"></script>

After this, the scripting error did not come.

You may like following Bootstrap SharePoint tutorials:

  • Bootstrap accordion example
  • Bootstrap 4 Forms Designing and Carousel Example
  • Bootstrap table
  • SharePoint Online branding: Creating Accordion Widget or Collapsible panel with Bootstrap
  • Creating Tabbed Menu using Bootstrap and HTML in SharePoint 2016/2013

I hope this tutorial helps to solve bootstrap’s javascript requires jquery error.

Bijay Kumar

I am Bijay a Microsoft MVP (8 times – My MVP Profile) in SharePoint and have more than 15 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com

1 answer to this question.

Hello @kartik,

You have provided wrong order for JAVASCRIPT and BOOTSTRAP

by convention bootstrap must follow jquery file definition

<!-- JQuery Core JavaScript -->
<script src="lib/js/jquery.min.js"></script>
<script src="lib/js/jquery-ui.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="lib/js/bootstrap.min.js"></script>

Hope this works!!

If you need to know more about javascript, then enroll now with our Java certification course online.

Thank You!!






answered

Apr 28, 2020


by
Niroj


• 82,840 points



Related Questions In JQuery

  • All categories

  • ChatGPT
    (4)

  • Apache Kafka
    (84)

  • Apache Spark
    (596)

  • Azure
    (131)

  • Big Data Hadoop
    (1,907)

  • Blockchain
    (1,673)

  • C#
    (141)

  • C++
    (271)

  • Career Counselling
    (1,060)

  • Cloud Computing
    (3,446)

  • Cyber Security & Ethical Hacking
    (147)

  • Data Analytics
    (1,266)

  • Database
    (855)

  • Data Science
    (75)

  • DevOps & Agile
    (3,575)

  • Digital Marketing
    (111)

  • Events & Trending Topics
    (28)

  • IoT (Internet of Things)
    (387)

  • Java
    (1,247)

  • Kotlin
    (8)

  • Linux Administration
    (389)

  • Machine Learning
    (337)

  • MicroStrategy
    (6)

  • PMP
    (423)

  • Power BI
    (516)

  • Python
    (3,188)

  • RPA
    (650)

  • SalesForce
    (92)

  • Selenium
    (1,569)

  • Software Testing
    (56)

  • Tableau
    (608)

  • Talend
    (73)

  • TypeSript
    (124)

  • Web Development
    (3,002)

  • Ask us Anything!
    (66)

  • Others
    (1,938)

  • Mobile Development
    (263)

Subscribe to our Newsletter, and get personalized recommendations.

Already have an account? Sign in.

Понравилась статья? Поделить с друзьями:
  • Uncaught error actions must be plain objects use custom middleware for async actions
  • Uncaught error a url property or function must be specified
  • Uncar dll вернул код ошибки 11
  • Unc ошибка mhdd
  • Unbuckling rear belt ошибка