Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

laidbackwebsage's avatar

SOLVED: Laravel-mix Issue: Popper.js dependency cannot be found by Boostrap 4 beta

I am trying to use Bootstrap 4 beta in my project. Bootstrap 4 beta requires Popper.js

My package.json, devDependencies looks like this:

"devDependencies": {
    "axios": "^0.16.2",
    "bootstrap": "^4.0.0-beta",
    "cross-env": "^5.0.1",
    "font-awesome": "^4.7.0",
    "jquery": "^3.1.1",
    "laravel-mix": "^1.0",
    "lodash": "^4.17.4",
    "popper.js": "^1.11.1",
    "vue": "^2.1.10"
  }

When I run npm run dev, I receive the following error:

 ERROR  Failed to compile with 1 errors                              11:01:21 AM

This dependency was not found:

* popper in ./resources/assets/js/bootstrap.js

To install it, you can run: npm install --save popper

I can confirm that Popper.js (the correct one) is installed and present in node_modules

Attempted Fixes:

  1. Copied node_modules/popper.js/dist/popper.js to resources/assets/js. Result: Same error.
  2. Copied node_modules/popper.js/dist/umd/popper.js to resources/assets/js. Result: Same error.
  3. Copied bootstrap.js from /var/www/data-ish/node_modules/bootstrap/dist/js to resources/assets/js. Result: Same error.
  4. In resources/assets/js/boostrap.js, add require('./popper'). Result: Same error. Removed.
  5. In resources/assets/js/boostrap.js, add require('./popper.js'). Result: Same error. Removed.
  6. Edited webpack.mix.js to:
let 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/assets/js/jquery.js',
    'resources/assets/js/popper.js',
    'resources/assets/js/bootstrap.js',
    'resources/assets/js/app.js',
    ], 'public/js')
    .autoload({
        jquery: ['jquery', 'jQuery', '$', 'window.jQuery'],
        Popper: ['popper', 'Popper', 'popper.js'],
        popper: ['Popper', 'popper.js'],
   })
   .sass('resources/assets/sass/app.scss', 'public/css');

Result: Same error.

How do I successfully get "popper.js" to be recognized and installed?

0 likes
10 replies
nwitthaus's avatar

From the error, it seems you are trying to require "popper" instead of "popper.js". If this doesn't fix it, please post your bootstrap.js file.

laidbackwebsage's avatar

SOLUTION

Edited my webpack.mix.js to this:

let 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.scripts([
    'resources/assets/js/jquery.js',
    'resources/assets/js/popper.js',
    'resources/assets/js/bootstrap.js',
    'resources/assets/js/app.js',
    ],'public/js/app.js').version();
mix.sass('resources/assets/sass/app.scss', 'public/css').version();

Result: DONE Compiled successfully in 2993ms

(Is it wrong when I feel good about solving my own problems?) :-D

laidbackwebsage's avatar

Better Solution

You need to use the umd version of popper.js.

webpack.mix.js:

let mix = require('laravel-mix').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 your application, as well as bundling up your JS files.
 |
 */

mix.autoload({
        jquery: ['$', 'window.jQuery',"jQuery","window.$","jquery","window.jquery"],
        'popper.js/dist/umd/popper.js': ['Popper']
    })
   .js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');

resources/assets/js/bootstrap.js:

window._ = require('lodash');

/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 * Include the Popper.js library, since Boostrap 4 requires it
 */
try {
  window.$ = window.jQuery = require('jquery');

  import Popper from 'popper.js/dist/umd/popper.js';
  window.Popper = Popper;
  
  require('bootstrap');
} catch (e) {}

/**
 * Vue is a modern JavaScript library for building interactive web interfaces
 * using reactive data binding and reusable components. Vue's API is clean
 * and simple, leaving you to focus on building your next great project.
 */

window.Vue = require('vue');

/**
 * We'll load the axios HTTP library which allows us to easily issue requests
 * to our Laravel back-end. This library automatically handles sending the
 * CSRF token as a header based on the value of the "XSRF" token cookie.
 */

window.axios = require('axios');

window.axios.defaults.headers.common = {
    'X-Requested-With': 'XMLHttpRequest'
};
10 likes
sitmgreg's avatar

confirmed that this will make Bootstrap 4 work with laravel 5.4.

In my case, I had to move the import outside of the try to compile w/o errors.

edit: ps nice work

2 likes
Cronix's avatar

It's best to have all of your vendor libraries in one file, and your app.js in a separate file. Reason being is your vendor libraries won't change as often as your app.js will, and no need to make the browser download everything again if only your app.js changed and none of the vendor libraries.

TimM1968's avatar

Having just been around the houses trying to integrate bootstrap-4 with auth I found this post which made things much easier: https://laravel-news.com/bootstrap-4-laravel-preset.

After creating a new project I just needed to run:

  1. composer require laravelnews/laravel-twbs4

  2. php artisan preset bootstrap4-auth

  3. npm install

  4. npm run dev

Hope this helps someone :-)

Massimiliano's avatar

Tried many of the solutions above but didnt work. So I just copied popper.js.map (the file that was missing) to public/js. I know, not elegant, but at least my console is quiet now

cristisst's avatar

well, i know that topic is very old but the issue is that the files with this line at the end:

//# sourceMappingURL=popper.js.map

will give you the headache and that error in Chrome/Firefox related to that file. What is doing actually is trying to load the map file from that location which when you compile the JS files all together there is being created just one map file (app.js.map or whatever is being called)

dawood's avatar

You can direct import like

import bootstrapBundle from './../../node_modules/bootstrap/dist/js/bootstrap.bundle.min.js';

no need to install popper

Please or to participate in this conversation.