我正在使用 .net 并构建打字稿模块并收到错误。 我想使用 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';
...
但这也行不通。
如何在我的打字稿文件中使用 bootstrap?
安装
npm install @types/jquery
npm install @popperjs/core
然后包含在您的 TS 文件中:
import * as $ from "jquery";
import Modal from "bootstrap/js/dist/modal";
您可能还需要安装 jquery(但先尝试不安装):
npm install jquery