3

I am getting below exception

bootstrap.js:240 Uncaught TypeError: Bootstrap's JavaScript requires jQuery. jQuery must be included before Bootstrap's JavaScript

at Object.jQueryDetection (bootstrap.js:240) at bootstrap.js:255 at bootstrap.js:9 at bootstrap.js:10

This is my code in Angular.json

"styles": [
  "src/styles.css",
  "node_modules/bootstrap/dist/css/bootstrap.css"
],
"scripts": 
[
  "node_modules/jquery/dist/jquery.js",
  "node_modules/bootstrap/dist/js/bootstrap.js"           
]

How can I fix this issue?

0

2 Answers 2

9

Surely "node_modules/jquery/dist/jquery.min.js" should come under "scripts"?

"styles": [
  "src/styles.css",
  "node_modules/bootstrap/dist/css/bootstrap.css"
],
"scripts": 
[
  "node_modules/jquery/dist/jquery.min.js",
  "node_modules/bootstrap/dist/js/bootstrap.js"           
]

And the now duplicated jQuery file ""node_modules/jquery/dist/jquery.js" should be removed.

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

2 Comments

Have you checked your file system to see that those file paths exist?
I made sure that jQuery and Bootstrap were properly installed into the project prior to adding these scripts. If jQuery is not installed you will get errors. The answer Kurt gave 100% correct.
3

If you want to use bootstrap in your application, or if you already have in your project, make sure to include jQuery before including the bootstrap JavaScript file. Bootstrap’s JavaScript file requires jQuery.

"scripts": [ "node_modules/jquery/dist/jquery.min.js",
           "node_modules/bootstrap/dist/js/bootstrap.js"]

After including jQuery, stop running your Angular CLI application. Then, re-run it using ng serve.

And then, if you want to use jQuery in your code at some point, all you have to do is to import it in whatever component you want to use jQuery.

import * as $ from 'jquery';

or

declare var $: any;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.