62

I have a fresh created Angular 4 CLI app. After running this:

npm install bootstrap@4.0.0-beta jquery popper.js --save

and editing .angular-cli.json like this:

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

I still have an issue in Chrome Console:

Uncaught Error: Bootstrap dropdown require Popper.js (https://popper.js.org)
    at eval (eval at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9), <anonymous>:6:17548)
    at eval (eval at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9), <anonymous>:6:23163)
    at eval (eval at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9), <anonymous>:6:50902)
    at eval (<anonymous>)
    at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9)
    at Object.../../../../script-loader/index.js!../../../../bootstrap/dist/js/bootstrap.min.js (bootstrap.min.js?f885:1)
    at __webpack_require__ (bootstrap a2f1d85ef068872b0530:54)
    at Object.2 (scripts.bundle.js:66)
    at __webpack_require__ (bootstrap a2f1d85ef068872b0530:54)
    at webpackJsonpCallback (bootstrap a2f1d85ef068872b0530:25)

How do I fix this?

mikebrsv
  • 1,890
  • 2
  • 24
  • 31

6 Answers6

139

Include popper.js before bootstrap.js:

"scripts": [
  "node_modules/jquery/dist/jquery.slim.min.js",
  "node_modules/popper.js/dist/umd/popper.min.js",
  "node_modules/bootstrap/dist/js/bootstrap.min.js"
],
Onome Sotu
  • 666
  • 9
  • 18
Joshua Colvin
  • 1,481
  • 1
  • 10
  • 7
  • 21
    Ensure that you add the version of popper.min.js in the ./dist/umd folder. This version ./dist/popper.min.js will cause issues with jquery. – Developer Wonk Aug 22 '17 at 15:40
  • What about `declare const $: any;` - is here any way to avoid this and have a result? – Sergey Sep 18 '17 at 20:42
  • @DeveloperWonk How do you know that the popper.js in "umd" folder is the correct one? – sanjihan Sep 19 '17 at 09:48
  • @DeveloperWonk Popper.js is currently shipped with 3 targets in mind: UMD, ESM and ESNext. UMD - Universal Module Definition: AMD, RequireJS and globals; ESM - ES Modules: For webpack/Rollup or browser supporting the spec; ESNext: Available in dist/, can be used with webpack and babel-preset-env; – Sergey Sep 19 '17 at 17:30
  • i'm a bit confused, don't you need to install typings for jquery/popper/bootstrap? – Cristian Sepulveda Sep 21 '17 at 15:18
  • 2
    Is there any reason to include the *.min.js version of the files? Won't Webpack minify the files when bundling them anyway? – Moulde Nov 01 '17 at 16:29
  • This solved a problem I was having with Bootstrap 4.2.1 dropdown, where the menu items were not being shown. Installing popper and jquery, then including these script dependencies worked for me. – Andrew Fielden Feb 10 '19 at 14:33
  • Please add a semicolon at the end of the second line – Farzan Najipour Aug 10 '19 at 09:37
  • Works perfectly on Angular 8 – C Alonso C Ortega Jan 15 '20 at 18:23
20

For Angular 7

npm install bootstrap jquery popper.js --save

       "styles": [
          "src/styles.scss",
          "node_modules/bootstrap/dist/css/bootstrap.min.css"
        ],
        "scripts": [
          "node_modules/jquery/dist/jquery.slim.min.js",
          "node_modules/bootstrap/dist/js/bootstrap.min.js",
          "node_modules/popper.js/dist/umd/popper.min.js"
        ],
Mustafa Omran
  • 354
  • 5
  • 7
15

Was same issue, when I updated app to 8 version of Angular. As solution can use bootstrap bundle minified js file instead bootstrap.min.js. Bootstrap bundle included popper.js already. Need to fix angular.json (scripts array in build section), in final will be something like this:

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

For this solution popper.js is not needed in project. Can remove this module:

npm uninstall popper.js

just in case, jquery needed :)

Hope, help you

Denis Anisimov
  • 685
  • 7
  • 11
7

Form Angular 8 to 13

npm install bootstrap jquery popper.js --save

     "styles": [
      "src/styles.scss",
      "node_modules/bootstrap/dist/css/bootstrap.min.css"
    ],
    "scripts": [
      "node_modules/jquery/dist/jquery.slim.min.js",
      "node_modules/popper.js/dist/umd/popper.min.js",
      "node_modules/bootstrap/dist/js/bootstrap.min.js"
    ],
Mustafa Omran
  • 354
  • 5
  • 7
0

The new https://www.npmjs.com/package/@popperjs/core doesnt work with bootstrap 5.

it still requires the old https://www.npmjs.com/package/popper.js?ref=vanillalist deprecated package.

tried in angular 13, it doesnt work, so have to fall back.

about14sheep
  • 1,813
  • 1
  • 11
  • 18
0

Angular with Bootstrap 5+ Since this version jQuery has been removed

npm i bootstrap popper.js*

 "styles": [
          "src/styles.scss",
          "node_modules/bootstrap/dist/css/bootstrap.min.css"
        ],
 "scripts": [
          "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
          "node_modules/popper.js/dist/umd/popper.min.js"
        ],
Mustafa Omran
  • 354
  • 5
  • 7