Webpack cannot resolve popper.js for Bootstrap
Module 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.
Fix it fast
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/core2Match what you see, then jump to its fix
- 1
The version is 4.x and the missing module is named popper.js.Bootstrap 4 is installed without Popper v1Fix - 2
The version is 5.x and the missing module is @popperjs/core.Bootstrap 5 is installed but @popperjs/core is missingFix - 3
The 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
- 1
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 bootstrap2Fix
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 buildConfirmed by getbootstrap.com
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 missing2Fix
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.js3Verify
Rebuild the project.
npm run buildConfirmed by getbootstrap.com
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.html2Fix
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
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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix