Having trouble getting Bootstrap 5 to work on Laravel 8? Don't worry, I've encountered the same issue but found

Is it possible to install Bootstrap 5 on Laravel 8?

After installing Bootstrap 5, jQuery, and Popper.js using the CDN version, I noticed that the dropdown menu and toggle button are no longer working, although my script is functioning correctly.

Here is the installation process I followed: https://www.youtube.com/watch?v=TKqJDWE0Wbo&ab_channel=NelisysDeveloper.

I suspect that there might be something missing regarding Popper.js since Bootstrap utilizes it, or there could be a conflict between JavaScript libraries.

Below are some files that might be helpful:

package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "mix",
        "watch": "mix watch",
        "watch-poll": "mix watch -- --watch-options-poll=1000",
        "hot": "mix watch --hot",
        "prod": "npm run production",
        "production": "mix --production"
    },
    "devDependencies": {
        "axios": "^0.21",
        "bootstrap": "^5.0.0-beta3",
        "fibers": "^5.0.0",
        "jquery": "^3.6.0",
        "laravel-mix": "^6.0.6",
        "lodash": "^4.17.19",
        "postcss": "^8.1.14",
        "resolve-url-loader": "^3.1.2",
        "sass": "^1.32.8",
        "sass-loader": "^8.0.0"
    },
    "dependencies": {
        "@popperjs/core": "^2.9.2"
    }
}

webpack.mix.js

const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */
mix.js('resources/js/app.js','public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .sourceMaps();

app.scss

// Fonts
@import url('https://fonts.googleapis.com/css?family=Nunito');

// Variables
@import 'variables';

// Bootstrap
@import '~bootstrap/scss/bootstrap';

bootstrap.js


    window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');

    require('bootstrap');

Answer №1

When transitioning from Bootstrap 4 to 5, you'll notice that Popper has been updated from version 1 to version 2. The package has undergone a name change and is now a scoped package. To guide you through this migration process, you can refer to the migration guide for Popper here.
As a result, you'll need to replace popper.js with @popperjs/core in bootstrap.js.

Furthermore, Bootstrap 5 no longer relies on JQuery.

Answer №2

It is highly recommended to refer to the latest version of Bootstrap's official documentation for the most up-to-date information.

One notable change to take note of is that the 'data-toggle' attribute has been updated to 'data-bs-toggle' in the current version.

Answer №3

I've encountered this issue as well while using popper with bootstrap on a project that is not Laravel-based. When I added popper and clicked on the dropdown in the navbar, I received a JS error related to popper.

The workaround I discovered was to only utilize bootstrap.bundle.js instead of separately incorporating bootstrap.js and popper.js.

For instance:

//Comment out these two:

<!--<script src="assets/js/popper.min.js"></script>-->
<!--<script src="assets/js/bootstrap.min.js"></script>-->

//Use this instead:

<script src="assets/js/bootstrap.bundle.min.js"></script>

For more details, refer to the first point in the overview section of the following page: getbootstrap.com/docs/5.0/components/popovers

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

What is the best way to set up playwright-jest so that I can skip a specific Test Suite (spec) file during execution?

In my repository, I have a setup using `playwright-jest` with multiple spec files for test suites. I need to skip one of the spec files without moving it from its current directory in the repo. The default script in `package.json` is `"test": "jest -c jes ...

remove CSS attribute from the JavaScript DOM properties

Can someone help me figure out what's wrong with my code? I need to remove all "link" tags with the attribute "rel = "stylesheet" Here is the HTML code I am working with: <html> <head> <title>teset</title> <meta charset="u ...

Create a set of n randomly generated points, represented as latitude and longitude pairs, originating from the central point of a polygon while remaining within the boundaries

I am currently trying to plot data within a polygon (District), but unfortunately, I do not have specific coordinates for each of the data sources in that district. My goal is to accurately display all the results from a district within its boundaries, wh ...

Guide on how to return a JSON result as a Dictionary instead of an Array using Express.js

I need to format my response as a dictionary with specific key-value pairs, like so: { "id": 5928101, "category": "animal welfare", "organizer": "Adam", "title": "Cat Cabaret& ...

configure various search parameters simultaneously during the rendering process

Incorporating a Tree component from mui v5, I am aiming to include searchParams for the selected and expanded nodes. This task is accomplished using the useSearchParams hook from React Router (v6). The issue arises when both the selected and expanded even ...

React has identified a modification in the sequence of Hooks invoked, however, I am unable to locate any Hooks being invoked conditionally

I am currently utilizing: ReactJS 16.14.0 In my React functional component, I am relying on data stored in context for accurate rendering. Certain data requires additional processing before display, and some data needs to be fetched. However, I am encoun ...

Leveraging JavaScript within a Polymer component

I have an object made with polymer: <newfolder-element id="newfolderelement" popupStyle="width: 362px; height: 100px;"> <span class="title">Create a new folder</span> <input type="text" class="ginput" style="width: 350px; padd ...

The functionality for the "OnChange" event in the <html:select> field does not seem to be functioning properly

My JavaScript function isn't functioning properly. I can't see any alert messages on my webpage. Can someone please assist me? Below is my HTML code function checkProjectStatus() { alert("Helloo"); var dropdownType = document.getElementById( ...

Adjust the time increment dynamically within the dropdown menu

I have a challenge to make a dynamic dropdown field that adjusts based on the value of a previous input field. There is a dropdown for selecting length, with options like 30 min., 60 min., and 90 min.. Additionally, there are input fields for startTime and ...

Generating consecutive numerical values within the auto table JSPDF column VusJs

https://i.sstatic.net/idhrw.png columns: [ { header: 'No', dataKey: 'Index', }, { header: 'No Registrasi', dataKey: 'no_register' }, { header: 'Kode Partai', data ...

The functionality of Bootstrap DataTable Sparkline is compromised when the table is configured to be responsive

I am working with a Bootstrap DataTable that includes a sparkline in the last column. Here is the complete JavaScript code: $(document).ready(function() { var groupColumn = 0; let table = $('#example').DataTable({ //responsive: true, ...

`returning a functional component directly from a component's event listener`

Recently, I started exploring React and came across an issue with React Router integration. I have a React menu component that includes hyperlinks in a sidenav for navigation to other components. However, the standard React Routing method doesn't see ...

SyntaxError: VM3419:1 - Unexpected token "<" was not caught

I'm exploring AJAX techniques in a demo project where I retrieve data from the server using AJAX methods. However, I encountered the following error: " Uncaught SyntaxError: Unexpected token< xhr.onreadystatechange @main.js" JS: (function ...

What is the best way to handle multiple promises when loading a state in Angular?

When loading the /home state, I need to retrieve all users from the database in order to customize the home controller and view based on the logged-in user. Currently, in the :resolve section of the state configuration, I am fetching all 'posts' ...

What is the implementation of booleans within the Promise.all() function?

I am looking to implement a functionality like the following: statusReady: boolean = false; jobsReady: boolean = false; ready() { return Promise.all([statusReady, jobsReady]); } ...with the goal of being able to do this later on: this.ready().then(() ...

Toggle checkbox feature in Bootstrap not functioning properly when placed within ng-view

When attempting to embed a bootstrap toggle checkbox within <ng-view></ng-view>, an issue arises where a regular HTML checkbox is displayed instead of the expected bootstrap toggle. Strangely, the same checkbox functions as a bootstrap toggle w ...

Step-by-step guide on setting up a click counter that securely stores data in a text file, even after the

Can anyone help me make this link actually function as intended? Right now it only runs the JavaScript code, but I would like it to run the code and redirect to a webpage. Additionally, I need the data to be saved to a text file. Please provide assistanc ...

When a Double Click event is activated in EaselJS, it also automatically triggers a Click event

Listening for Events function Solitaire() { this.table.addEventListener("click", this.handleClick.bind(this)); this.table.addEventListener("dblclick", this.handleDoubleClick.bind(this)); } Event Handling Solitaire.prototype.handleDoubleClick = f ...

Tips for retrieving the identifier of a row in a mui datagrid when an onClick event occurs

I'm attempting to integrate a material-ui datagrid with a sql database for the purpose of enabling edits to be made via a form rather than editing individual rows and cells one by one. My goal is to pass the row's id as a parameter to a function ...

Can the tooltip of an element be changed while the old tooltip is still visible without having to move the mouse away and then back again?

When I have an HTML anchor element with a tooltip that appears when the mouse is hovered over it, and then I use JavaScript to change the tooltip's text using element.title = "Another Tooltip", the new tooltip text does not immediately update visually ...