我将 VisualStudio 2019 与 TypeScript3.9 和 Libman 一起使用。
我需要 Bootstrap4 和 jQuery。因此,请尝试通过 Libman 获取这些库和类型(index.d.ts)。
然后 Bootstrap4 键入(index.d.ts)得到错误“找不到模块 popper.js”。
// Type definitions for Bootstrap 4.5
// Project: https://github.com/twbs/bootstrap/, https://getbootstrap.com
// Definitions by: denisname <https://github.com/denisname>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="jquery"/>
import * as Popper from "popper.js"; // ERROR!: "Cannot find module popper.js"
我发现了类似的问题和答案。
- Bootstrap 4 TypeScript 类型定义无法编译 - 找不到模块'popper.js'
- 找不到模块“popper.js”Angular 5 Visual Studio 2017 asp.net 核心
- Angular @types/bootstrap 错误:命名空间“popper.js”没有导出成员
只能暂时解决问题。
我将 bootstrap4 typing(index.d.ts) 更改为相对路径,这import * as Popper from "../popper_v1";
是固定错误。但是 Libman 会覆盖这个手动更改的 index.d.ts。
_
我能做些什么来解决这个错误?我是否需要安装手动修改的 index.d.ts,比如 Popper v1.X?
谢谢。
重现错误的步骤。
在 .Net Framework 4.8 上创建 ASP.Net4 MVC 项目
创建 libman.json 以添加一些库和 TS 类型
{
"version": "1.0",
"defaultProvider": "jsDelivr",
"libraries": [
{
"library": "bootstrap@4.5.2",
"destination": "lib/bootstrap/"
},
{
"library": "@types/bootstrap@4.5.0",
"destination": "lib/types/bootstrap/"
},
{
"library": "jquery@3.5.1",
"destination": "lib/jquery/",
"files": [
"dist/jquery.js",
"dist/jquery.min.js",
"dist/jquery.min.map",
"dist/jquery.slim.js",
"dist/jquery.slim.min.js",
"dist/jquery.slim.min.map",
"external/sizzle/LICENSE.txt",
"external/sizzle/dist/sizzle.js",
"external/sizzle/dist/sizzle.min.js",
"external/sizzle/dist/sizzle.min.map",
"AUTHORS.txt",
"LICENSE.txt",
"README.md"
]
},
{
"library": "@types/jquery@3.5.1",
"destination": "lib/types/jquery/"
},
{
"library": "@types/sizzle@2.3.2",
"destination": "lib/types/sizzle/"
},
{
"provider": "cdnjs",
"library": "popper.js@1.16.1",
"destination": "lib/popper.js/"
},
{
"provider": "filesystem",
"library": "lib_ManualInstallSources/popper_v1/",
"destination": "lib/types/popper_v1/"
}
]
}
** 注意:我从 GitHub 存储库中获得了 popper.js ver.1.X 的类型(index.d.ts)。
- 创建 tsconfig.json
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"lib": [ "ES6", "DOM" ],
"baseUrl": ".",
"typeRoots": [
"./lib/types"
]
},
"exclude": [
"node_modules",
"wwwroot",
"lib"
]
}
完成这些步骤后,bootstrap4 typing(index.d.ts) 得到错误“找不到模块 popper.js” import * as Popper from "popper.js";
。