Typescript Bootstrap互操作:导入和使用Bootstrap模块引发错误:生成:无法找到模块“@popperjs/core”

k3fezbri  于 9个月前  发布在  Bootstrap
关注(0)|答案(1)|浏览(159)

我正在使用.net构建一个typescript模块,并得到一个错误。我想从Typescript使用Bootstrap并通过NPM安装它。
我有这样的东西:

import {Modal} from 'bootstrap';

function showModal(id: string) {
    const el = document.getElementById(id);
    let modal = Modal.getInstance(el);
    if (modal == null) {
        modal = new Modal(el);
    }
    modal.show();
}

字符串
然而,当我编译这段代码时,我得到了多个错误:

dropdown.d.ts(1, 25): [TS2792] Build:Cannot find module '@popperjs/core'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

tooltip.d.ts(1, 25): [TS2792] Build:Cannot find module '@popperjs/core'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?


我尝试通过npm install @popperjs/core安装丢失的模块,并包括通过:

import "@popperjs/core"
import {Modal} from 'bootstrap';
...


但这也不起作用。
如何在我的typescript文件中使用bootstrap?

dly7yett

dly7yett1#

安装

npm install @types/jquery
npm install @popperjs/core

字符串
然后在TS文件中包含:

import * as $ from "jquery";
import Modal from "bootstrap/js/dist/modal";


您可能还需要安装jquery(但首先尝试不安装):

npm install jquery

相关问题