Typescript Bootstrap 互操作:导入和使用 Bootstrap 模块会引发错误:构建:找不到模块“@popperjs/core”

问题描述 投票:0回答:1

我正在使用 .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?

typescript twitter-bootstrap
1个回答
0
投票

安装

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

然后包含在您的 TS 文件中:

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

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

npm install jquery
© www.soinside.com 2019 - 2024. All rights reserved.