Encountering a problem with loading popper.js in Bootstrap 4 while utilizing require.js for loading

After installing bootstrap 4, jquery, and popper via npm, I encountered an error in the console when loading my website. The error indicated that the file popper.js could not be retrieved. Upon further inspection, I found that there were two instances of popper.js - one loaded successfully by require.js with a path of

http://localhost:9000/Libs/popper.js/dist/umd/popper.js
, and another one not found by bootstrap with a path of http://localhost:9000/popper.js.

In the images below, pic 1 displays the configured paths for the JS library, pic 2 shows the successful loading of libraries, and pic 3 highlights the failure to load popper.js.

I am puzzled as to why bootstrap is unable to recognize that popper.js has been loaded by require.js.

If anyone could offer insight into this issue, I would greatly appreciate it. Thank you!

https://i.sstatic.net/kLc6f.png

Answer №1

Consider the following options:

bootstrap.bundle.js

or:

bootstrap.bundle.min.js

https://getbootstrap.com/docs/4.0/getting-started/contents/

The documentation specifies that these files include popper, eliminating the need for a separate requirement.

If you encounter issues, check your source files for /popper.js as it might be a simple reference correction elsewhere.

Instead of:

require(["bootstrap"], function(bootstrap) {
    // do nothing
});

Try this approach to load popper first:

require(["popper"], function(popper) {
    window.Popper = pop
    require(["bootstrap"]);
});

Alternatively, you can utilize the CDN links recommended by Bootstrap before adding the compiled bootstrap code.

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>

Answer №2

Greetings! This marks my debut response on a stackoverflow inquiry, and given my personal battle with it, I felt compelled to share my solution. As echoed by previous responses, bootstrap necessitates the presence of popper js. However, bootstrap locates popper at the root level—regardless of its actual location in the directory structure. Dive into the code snippet below, showcasing the utilization of require('popper.js'):

bootstrap.js

The resolution lies in specifying the module "popper.js" using require function, precisely as follows:

require.config({
baseUrl: 'lib',
paths: {
    main: 'main',
    jquery: 'jquery/dist/jquery',
    'jquery-slim': 'jquery/dist/jquery-3.3.1.slim.min',
    'jqueryUnobtrusive': 'jquery-validation-unobtrusive/jquery.validate.unobtrusive',
    'bootstrap': 'bootstrap/dist/js/bootstrap',
    'knockout': 'knockout/knockout-latest',
    'ajax': 'jquery-ajax/jquery.unobtrusive-ajax',
    'shop': '/scripts/shop/shop',
    'domready': 'requirejs/domready',
    'shoporder': '/scripts/shoporder/shoporder',
    'popper': 'popper.js/dist/umd/popper'
}});

define("popper.js", ['popper'], () => {
require(['popper'], () => {
    require(['bootstrap']);
});

define(['main', 'jquery', 'jquery-slim'], () => {
 require(['jqueryUnobtrusive', 'ajax']);
 require(['knockout']);
 require(['jquery']);
 require(['popper.js']);
});

This approach ensures that bootstrap successfully navigates to the correct directory.

Answer №3

To ensure Bootstrap works properly, Popper must be accessible in the global scope. You can resolve this issue by including exports in the shim configuration:

shim: {
    bootstrap: {
        deps: ['jquery','popper']
    },
    popper: {
        exports: "Popper"
    }
}

Additionally, it's important to confirm that Bootstrap correctly specifies the module name. This can be verified at the beginning of the bootstrap.js file.

(function (global, factory) {   
  typeof exports === 'object' && typeof module !== 'undefined' 
  ?  factory(exports, require('jquery'), require('popper')) 
  :  typeof define === 'function' && define.amd 
  ? define(['exports', 'jquery', **'popper'**], factory) 
  : (...)

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

Enhancing User Experience with AJAX-loaded Navigation Bar

I have set up the following structure: A main-page.php consisting of: 1) A header 2) A navigation bar 3) Content (loaded inside a <div id="dynamic-content"></div>) 4) Footer The navigation bar contains various options (e.g. About Us, Cont ...

What is the best way to control the iteration of a JavaScript 'for' loop based on specific conditions?

I need help with controlling the iteration of a 'for' loop in Javascript. Here is the code snippet: for (var j=0; j < number; j++){ $('#question').empty; $('#question').append('' + operand1[j], operator[j ...

Activate a .click() event on a hyperlink exclusively in mobile view

Currently, I am working on a WordPress website that utilizes a Table of Contents plugin. The plugin simply identifies headings and adds them to the table of contents. I am aiming to achieve a specific functionality on my website (). When the window width ...

I'm having trouble finding the solution to setting a token in my request header

I have been following a tutorial in a book to build the authentication for my app. However, I am facing an issue where after logging in correctly, I am unable to set the token back into the request. The error message that I receive is: Failed to execute ...

Does angular-sortablejs work with angular 5?

I attempted to use angular-sortables in combination with the ng-drag-drop library to sort the list items that are being dragged, but it appears that nothing is happening when I try to use it. Does anyone know if angular-sortables is compatible with Angular ...

Jquery ripple effect does not function properly with background-attachment: fixed style

Is there a way to make the effect ripples () work with background-attachment: fixed? I'm trying to achieve this effect while keeping the background fixed in place. Any suggestions on how to make this work? background-attachment: fixed; ...

What steps can be taken to diagnose the cause of a failed Jquery AJAX request?

I am attempting to utilize the Yahoo Finance API to retrieve data in CSV format through Javascript. However, my current implementation shown below is not successful. $.ajax({ type: "GET", url: "http://finance.yahoo.com/d/quotes.csv?s=RHT+MSFT&f=sb2b3j ...

What is the best way to transfer a value to v-model using emit?

I'm having trouble passing the selected value from a select field to v-model. Currently, the code only seems to work with a v-text-field. <script> export default { name: 'FormSelect', props: { model ...

Error on my React website: Exceeded the maximum call stack size

I am currently utilizing the useEffect hook within my React component to update a local state whenever there is a change in the global redux state. The issue arises in my component when trying to update imgList upon receiving updated photos using useSelec ...

Displaying an IP camera feed on a three.js canvas

I've been presented with a seemingly straightforward task in JavaScript that I'm not very familiar with. The challenge is to take an IP camera stream and display it on a three.js canvas. To start, I came across an example that uses a webcam inst ...

What is the best way to prevent state persistence in Next.js dynamic routes?

Currently, I'm constructing a headless eCommerce platform using React/Next. In this setup, I have a [product].js dynamic route that generates all product pages utilizing the getStaticPaths() and getStaticProps() functions successfully. Within the [pr ...

Encountered an issue when executing "npm start": The system does not recognize 'next' as a valid internal or external command

Encountering an issue when running the "npm start" command in the terminal while attempting to create a cryptocurrency tracker using React.js Displayed contents of my package.json file: { "name": "nextjs-crypto-api", "version ...

The getBBox() method of SVG:g is returning an incorrect width value

Hey there, I've been attempting to determine the width of a <g> element and it consistently returns 509.5 pixels regardless of what I do. Initially, I assumed this was the actual size and not scaled. However, upon opening the SVG in Illustrato ...

Blurry text issue observed on certain mobile devices with Next.js components

There continues to be an issue on my NextJS page where some text appears blurry on certain mobile devices, particularly iPhones. This problem is only present on two specific components - both of which are interactive cards that can be flipped to reveal the ...

Altering the Color of Items in an ASP.NET ListBox

I have a listbox on a webform that is being populated by a datasource from a SQL Server 2008. Based on the text in the list box, I want the background color of each specific item to be different. For example, if these are the items in the list: AA item ...

What is the process for embedding a Vue app within another Vue app?

I have been tasked with creating a widget that will be integrated into various customers' websites. Think about something like this: https://i.sstatic.net/3uKwL.png There are 2 constraints: The use of iframes is not allowed The customers' we ...

What is the process for transferring a JavaScript variable to a Java servlet?

I am trying to send a JavaScript variable to a Java servlet in a web application I am developing. Below is the HTML code: <p id="test">Some text</p> Here is the JavaScript code I am using: var myVar = document.getElementById('test' ...

One module triggers nodeMailer to send an email, while the other does not request it

My website needs to send two different types of emails: One type is a randomly generated password sent to a user who requests it (from the PayAsYouLike module). The other type is a 'get-in-touch' form that sends the email to my personal account ...

What impact do the input values of an Angular reactive form have on the DOM?

I am currently working on developing a UI wizard app using Angular (reactive forms) version 6/7. The main purpose of this app is to enhance the product page of an ecommerce platform such as Shopify or WordPress. I am utilizing angular material radio inputs ...

Struggling to reach the same level of bundle optimization with webpack + angular when compared to angular-cli

I am currently facing an issue with two Angular projects that I have. One is developed using angular-cli, while the other one is built with Webpack and utilizes @ngtools/webpack. Both projects are based on Angular 7.1.4 and @angular-devkit 0.13.5. The code ...