I want to incorporate the Bootstrap Modal
component into my TypeScript application.
Therefore, I added the necessary types:
npm i @types/bootstrap
After that, in my TypeScript code:
import { Modal } from "bootstrap";
const myModal = new Modal('#myModal');
But when I try to compile the code, I encounter the following error:
TS2792: Cannot find module '@popperjs/core'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? 1 import * as Popper from '@popperjs/core'; ~~~~~~~~~~~~~~~~ node_modules/@types/bootstrap/js/dist/tooltip.d.ts:1:25 - error TS2792: Cannot find module '@popperjs/core'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? 1 import * as Popper from '@popperjs/core'; ~~~~~~~~~~~~~~~~ Found 2 errors in 2 files. Errors Files 1 node_modules/@types/bootstrap/js/dist/dropdown.d.ts:1 1 node_modules/@types/bootstrap/js/dist/tooltip.d.ts:1
Following the error message's advice and adding
"moduleResolution": "NodeNext"
allows for successful compilation. However, a runtime error appears in the console:
Uncaught TypeError: Failed to resolve module specifier "bootstrap". Relative references must start with either "/", "./", or "../".
So, how can I use a Bootstrap modal with TypeScript?