Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Webpack cannot resolve popper.js for Bootstrap

ErrorModule not found: Error: Can't resolve 'popper.js'

Short answer

Bootstrap loads Popper for dropdowns, tooltips and popovers, and the two major versions use different packages. Bootstrap 4 needs Popper v1 (the popper.js package). Bootstrap 5 needs Popper v2 (@popperjs/core). Install the one that matches your Bootstrap version, or use the bundle build that includes it.

  • Applies to Node.js 22, Bootstrap 4.6, Bootstrap 5.3, Popper 1.16, Popper 2.11
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out which Bootstrap version the project has. The answer decides which Popper package is correct.

    npm ls bootstrap popper.js @popperjs/core
  2. 2Match what you see, then jump to its fix

    1. 1The version is 4.x and the missing module is named popper.js.Bootstrap 4 is installed without Popper v1Fix
    2. 2The version is 5.x and the missing module is @popperjs/core.Bootstrap 5 is installed but @popperjs/core is missingFix
    3. 3The error comes from the browser console, not from a bundler, and it names the bare specifier @popperjs/core.A plain browser page imports Bootstrap as an ES moduleFix

What does the error look like?

  • Module not found: Error: Can't resolve 'popper.js'
  • Module not found: Can't resolve '@popperjs/core'

Cause 1 of 3

Bootstrap 4 is installed without Popper v1

1Check

Bootstrap 4 treats Popper as an optional dependency that the compiled files do not include, and its docs load Popper 1.16.1 before bootstrap.min.js.

npm ls bootstrap

2Fix

Install Popper v1 next to Bootstrap 4. If you would rather not manage it, import the bundle file, which is the Bootstrap 4 build meant to include Popper.

npm install popper.js@1.16.1

// or, without a separate Popper package
import 'bootstrap/dist/js/bootstrap.bundle.min.js';

3Verify

Restart the dev server or rebuild. The module error should be gone.

npm run build

Confirmed by getbootstrap.com

Did this fix it?

Cause 2 of 3

Bootstrap 5 is installed but @popperjs/core is missing

1Check

Bootstrap 5 moved from Popper v1 to Popper v2, and its ES module build imports the package @popperjs/core. An old popper.js package does not satisfy that import.

ls node_modules/@popperjs/core 2>/dev/null || echo missing

2Fix

Install the Popper v2 package. Remove popper.js if it was added by an old Bootstrap 4 setup.

npm install @popperjs/core
npm uninstall popper.js

3Verify

Rebuild the project.

npm run build

Confirmed by getbootstrap.com

Did this fix it?

Cause 3 of 3

A plain browser page imports Bootstrap as an ES module

1Check

bootstrap.esm.js contains import * as Popper from "@popperjs/core". A browser cannot resolve a bare package name unless an import map tells it where the file is.

grep -n "importmap" index.html

2Fix

Add an import map that points both names to full URLs, as in the Bootstrap docs.

<script type="importmap">
{
  "imports": {
    "@popperjs/core": "https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/esm/popper.min.js",
    "bootstrap": "https://cdn.jsdelivr.net/npm/bootstrap@5.3.9/dist/js/bootstrap.esm.min.js"
  }
}
</script>

3Verify

Reload the page and open the console. The resolve error should not appear.

console.log(typeof bootstrap.Dropdown)

Confirmed by getbootstrap.com

Did this fix it?

How do I stop it coming back?

  • Pin Bootstrap and Popper together in package.json and upgrade them as a pair.
  • After a Bootstrap major upgrade, read the migration page: it lists the Popper change.
  • Do not mix a Bootstrap 4 tutorial's install commands into a Bootstrap 5 project.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.