Fixing the Bootstrap 4 issue "Popper.js required for Bootstrap dropdowns" using Aurelia CLI and Require.js

Struggling to set up Bootstrap 4 beta in an Aurelia CLI app (v0.31.1) with requirejs and TypeScript. Despite trying different configurations, the console consistently shows this error:

Uncaught Error: Bootstrap dropdown require Popper.js

Here's a breakdown of the steps taken. First, install the necessary packages:

$ npm install --save jquery <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9bf9f4f4efe8efe9faebdbafb5abb5abb6f9feeffa">[email protected]</a> popper.js

Then, adjust aurelia.json:

  "jquery",
  {
    "name": "popper.js",
    "path": "../node_modules/popper.js/dist/umd",
    "main": "popper"
  },
  {
    "name": "bootstrap",
    "path": "../node_modules/bootstrap/dist",
    "main": "js/bootstrap.min",
    "deps": [
      "jquery",
      "popper.js"
    ],
    "exports": "$",
    "resources": [
      "css/bootstrap.css"
    ]
  }

Key points from the configuration above:

  • popper.js is declared before bootstrap
  • UMD module is selected
  • popper.js is listed as a dependency for bootstrap along with jquery

Lastly, in app.ts:

import 'bootstrap';

After setting up the configuration, building with au build proceeds without issues. However, when running with au run --watch, errors emerge in the console:

Uncaught Error: Bootstrap dropdown require Popper.js () (defaults.js:19)
Uncaught Error: Bootstrap dropdown require Popper.js () (bootstrap.min.js:6)
... further down:
Uncaught TypeError: plugin.load is not a function at Module. (defaults.js:19)

Unfortunately, Bootstrap 4 documentation offers guidance only for webpack setups. Searches on Aurelia's Gitter.im channel and StackOverflow fail to provide examples for Aurelia CLI with Require.js. Google results mainly cover alpha versions that used 'tethering' instead of 'popper'.

Other questions on SO with similar errors don't fit my situation:

  • Bootstrap 4 Beta importing Popper.js with Webpack 3.x throws Popper is not a constructor
  • Angular 4 Bootstrap dropdown require Popper.js
  • And several more...

So, the question remains: how can Bootstrap 4 be configured with Popper.js in an Aurelia CLI app using Require.js, not Webpack?

Thank you.

Answer №1

Popper took over for Tether during the beta phase.

To implement this change, you'll need to replace Tether with Popper in the prepend section of your aurelia.json file. If you never had the alpha version, simply add it. Make sure to link to the UMD version as shown below:

"prepend": [
   ...
          "node_modules/jquery/dist/jquery.js",
          "node_modules/popper.js/dist/umd/popper.min.js",
   ...
     ]

Bundling is also necessary and should be structured like so:

      {
        "name": "bootstrap4",
        "path": "../node_modules/bootstrap/dist",
        "main": "js/bootstrap.min",
        "deps": [
          "jquery"
        ],
        "exports": "$",
        "resources": [
          "css/bootstrap.css"
        ]
      }

=Addendum=

In contrast to Tether, Popper might not require prepending. Thus, you can include it like any other dependency:

 {
     "name": "popper.js",
     "path": "../node_modules/popper.js/dist/umd",
     "main": "popper.min"
 },

Answer №2

I removed popper.js from my system and integrated the version that comes with bs4 by utilizing js/bootstrap.bundle.min in place of js/bootstrap.min

  "jquery",
  {
    "name": "bootstrap",
    "path": "../node_modules/bootstrap/dist",
    "main": "js/bootstrap.bundle.min",
    "deps": ["jquery"],
    "exports": "$",
    "resources": [
      "css/bootstrap.css"
    ]
  },

Answer №3

Insert your code here.

<!-- Include Optional JavaScript -->
    <!-- Start with jQuery, followed by Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

Answer №4

Here is the solution that worked for me by using the bundled version of BS4:

To start, remove popper: npm uninstall popper.js

Next, update to BS4 or a later version with this command: npm install bootstrap --save

Ensure jquery is installed as well using: npm install bootstrap --save

Then, don't forget to modify `.angular-cli.json' to include jquery and the bundled BS4 library:

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

Answer №5

A working configuration for Bootstrap with Popper in the final version of Bootstrap 4.0 can be found below:

//file; aurelia_project/aurelia.json
"dependencies": [   
    ...
    ... // other dependencies
    ...

   "text",
   "jquery",
   {
     "name": "popper.js",
     "path": "../node_modules/popper.js/dist/umd",
     "main": "popper.min"
   },
   {
     "name": "bootstrap",
     "path": "../node_modules/bootstrap/dist",
     "main": "js/bootstrap.min",
     "deps": ["jquery"],
     "exports": "$",
     "resources": [
       "css/bootstrap.css"
     ]
   },
...
... // remaining dependencies
...
],

This setup is compatible with the latest versions of Aurelia and Bootstrap (as of February 2018) and does not require using the prepend method.

Answer №6

Bootstrap 4 has made it easier than ever to integrate by simply adding this line:

<script type="text/javascript" src="/assets/vendor/bootstrap/dist/js/bootstrap.bundle.min.js">
</script>

The file already includes Popper.js. Refer to the bootstrap documentation on dropdowns for more information: https://getbootstrap.com/docs/4.0/components/dropdowns/#overview

Note: You will need to have Bootstrap 4 installed. While this may not be the exact solution you're looking for, it could be extremely helpful for those not using Aurelia CLI and Require.js.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with Boostrap collapse functionality not functioning correctly on live website, although it is working as intended in local environment

I am experiencing an issue with the collapsible navbar on my website. It is not closing smoothly as it should, despite being correctly implemented. The website is built using Bootstrap 4 and Jekyll, with a gulpfile for minifying and concatenating HTML, CSS ...

group items into ranges based on property of objects

I've been grappling with this issue for far too long. Can anyone provide guidance on how to tackle the following scenario using JavaScript? The dataset consists of objects representing a date and a specific length. I need to transform this list into a ...

Is there a way to verify the presence of data and halt code execution if it is not found?

In my data, there is a table containing a total of 5 links. The first 2 links can vary in availability as they are dynamic, while the last 3 links are static and are always displayed. The dynamic links' data is deeply nested within the state object, s ...

What is the method for exporting all functions from a TypeScript file with a default export included?

An example of the export type mentioned is React. To use it, we can include the following code: import React, {Component} from "react". This allows us to access both React.Component and Component. What steps are necessary to make this possible? ...

Guide for nesting components in Storybook using Angular

I am currently working with a folder structure that contains both my button and card components: https://i.sstatic.net/fNa0t.png To organize my components, I created a components.module.ts file and placed all my components in it. Then, I imported it into ...

Leveraging scanner-js within an Angular2 environment

Exploring ways to incorporate Scanner-JS into my Angular2 project, a tool I discovered while tinkering with the framework. Being a novice in Angular2, this question might be elementary for some. I successfully installed scanner-js via npm npm install sc ...

Enhance JSON for efficiency in Typescript Mapping

In my Java to Typescript data transfer, I am encountering an issue with objects containing "Map" properties. To define my Typescript models, I use interfaces instead of classes: export interface Foo { bar: Map<string, Bar>; mapOfBar: Map< ...

Retrieve an array of specific column values from an array of objects using Typescript

How can I extract an array from an array of objects? Data var result1 = [ {id:1, name:'Sandra', type:'user', username:'sandra'}, {id:2, name:'John', type:'admin', username:'johnny2'}, ...

Attempting to implement a button element in a reactstrap card to toggle the visibility of the card's text

Is there a way to implement a toggle feature for the card text ({card.description}) by clicking on the detail button? Do I need to use a state function or is there a simpler method using collapse? I would like the card image and title to always be displaye ...

Tips on turning off automatic positioning in Bootstrap 4.1

My dropdown list is currently quite large. Take a look at the image linked below. Image How can I address this issue effectively? I'm considering utilizing JavaScript to reposition the menu. Any guidance on how to disable auto-positioning? Check ou ...

Starting value within angular's toSignal()

Experiencing frustration with setting initialValue to true for a signal, encountering the error message (TS2769: No overload matches this call). The Observable does return an Observable. A workaround was found by omitting the "initialValue" option and ad ...

Error: Bootstrap 4 Container Size Issue

I am having an issue with the width of my footer when using a Bootstrap 4 "Container". The Container does not cover the entire bottom of the screen as expected. Even changing it to Container-Fluid does not resolve the issue. For reference, here is a JSFid ...

Subscription Code Incrementally Triggering Upon Each Component Load

Within the initialization of my component, I have the following code: public Subscription: Subscription; ngOnInit() { this.subscription = this.myService.currentData.subscribe( dataReceived => { this.data = dataReceived; this.useDa ...

Experiencing a problem with the bundle.js file in Angular Universal

My Angular build is giving me this error in the web browser: Uncaught SyntaxError: expected expression, got '<' in bundle.js When I run the command npm run dev:ssr, no errors are generated. However, when I try to access the application, the ...

The issue with the antd Input component's onChange event not updating state correctly when using a list fetched from an axios get request in a React

Recently delving into React, I've dedicated the past week to honing my skills. My current project involves creating a straightforward application featuring a 'product create' form alongside a product list equipped with a search bar (utilizin ...

Bootstrap 4 Multilevel Navbar with Bootswatch design positioned on the right side

How can I modify a multilevel Navbar in Bootswatch 4 (Bootstrap 4) to make the Submenus pop open to the left side? The "dropdown-menu-right" class doesn't achieve the desired result. Can someone provide guidance on how the CSS / Javascript should be a ...

Include data types when destructuring arrays within a loop

Is it possible to use type annotations in for...of loops in TypeScript? For example, like this for array destructuring: for(let [id, value]: [string, number] of Object.entries(some_object)) { } Or perhaps like this for object destructuring: for(let {a, b} ...

Setting up a React state with an Object using Typescript: A step-by-step guide

As someone who is new to TypeScript, I have a solid understanding of how to set up an interface for certain types. However, I am struggling to comprehend how the same concept would apply to an Object type. interface MyProps { defaultgreeting: 'He ...

Searching for data based on specific keywords in Angular 2, rather than using a wildcard search, can be done by utilizing the key-in

My dropdown contains 100 values, and I am currently able to search for these values based on key input using wild search. However, I would like the dropdown to display values based on the specific alphabet that I enter first. HTML: <div class="col- ...

How can I utilize Material-UI's DataGrid component to incorporate multiple layers of text within a single cell?

I'm having trouble displaying two separate lines of text in a single cell using Material-UI's datagrid component. Here is the code I have attempted: const columns: ColDef[] = [ { field: "name", headerNam ...