Bootstrap4键入(index.d.ts)找不到模块';popper.js';使用TypeScript3.9和Libman的VisualStudio 2019

Bootstrap4键入(index.d.ts)找不到模块';popper.js';使用TypeScript3.9和Libman的VisualStudio 2019,typescript,visual-studio,bootstrap-4,typescript-typings,libman,Typescript,Visual Studio,Bootstrap 4,Typescript Typings,Libman,我将VisualStudio2019与TypeScript3.9和Libman一起使用 我需要Bootstrap4和jQuery。 所以试着用Libman获得这些库和打字(index.d.ts) 然后Bootstrap4键入(index.d.ts)得到错误“找不到模块popper.js” //引导程序4.5的类型定义 //项目:https://github.com/twbs/bootstrap/, https://getbootstrap.com //定义:denisname //皮奥特·贝亚耶

我将VisualStudio2019与TypeScript3.9和Libman一起使用

我需要Bootstrap4和jQuery。 所以试着用Libman获得这些库和打字(index.d.ts)

然后Bootstrap4键入(index.d.ts)得到错误“找不到模块popper.js”

//引导程序4.5的类型定义
//项目:https://github.com/twbs/bootstrap/, https://getbootstrap.com
//定义:denisname
//皮奥特·贝亚耶维奇
//定义:https://github.com/DefinitelyTyped/DefinitelyTyped
//打字稿版本:2.3
/// 
从“Popper.js”导入*作为Popper;//错误!:“找不到模块popper.js”

我发现了类似的问题和答案

它只能暂时解决这个问题

我将bootstrap4类型(index.d.ts)从“./Popper_v1”更改为相对路径,作为“
import*as Popper”已修复错误。
但是Libman会覆盖这个手动更改的index.d.ts

_

我可以做什么来修复此错误? 我是否需要安装手动修改的index.d.ts,比如popperv1.X

谢谢


报告错误的步骤。
  • 在.Net Framework 4.8上创建ASP.Net4 MVC项目

  • 创建libman.json以添加一些库和TS类型

  • **注意:我从GitHub存储库中获得了popper.js版本1.X的输入(index.d.ts)

  • 创建tsconfig.json
  • 在这些步骤之后,bootstrap4键入(index.d.ts)在
    import*上得到错误“找不到模块popper.js”,作为“popper.js”中的popper


    我找到了两个要修理的小东西。
  • 将tsconfig.json设置更改为编译器可以搜索“lib”目录
  • 通过Libman将库的目录名更改为“node_modules”(不推荐)
  • 这个问题是由多种原因造成的。
  • TypeScript的默认模块管理机制基于node.js
  • 默认情况下,Libman使用“lib”目录放置库
  • 库的目录名必须与ModuleName相同

  • [理由] 1.TypeScript的模块管理机制基于node.js。 我的tsconfig.json有
    “目标”:“ES5”
    。并且没有
    “模块”
    属性

    它将
    “模块”
    属性设置为默认值。在
    “ES5”
    目标下,默认值为
    “CommonJS”

    那么,也就没有“moduleResolution”属性了。 因此
    “模块”:“CommonJS”
    “模块解决方案”
    属性设置为
    “节点”

    是,编译器使用“节点”模块解析系统。

    >TypeScript 3.9上的“节点”解析系统 也就是说,非相对导入(例如,
    import*from“banana”
    )将递归搜索“node\u modules”目录(到父目录)

    是,目录必须命名为“节点\模块”

    否则我们使用Libman,但最新的typesccript的基本理论是基于“node.js”
    而“经典”的分辨率系统是遗留的,毫无用处

    最后,我们需要更改tsconfig.json以搜索“lib”目录。 或者将目录名更改为“node_modules”,以调整为“node”解析系统(不推荐。我们使用Libman,而不是node)


    2.默认情况下,Libman使用“lib”目录放置库。 由于1的原因,我们需要“node_modules”目录。 但是libman的默认目录名是“lib”

    这导致编译器无法在“lib”目录上搜索库


    3.库的目录名必须与ModuleName相同。 如果使用非相对导入(例如从“香蕉”
    )导入*),编译器搜索“/node\u modules/banana.js(ts)”或“/node\u modules/banana/*”

    我的libman.config输入了popper.js 1.X版的(.d.ts)

    {
      "provider": "filesystem",
      "library": "lib_ManualInstallSources/popper_v1/",
      "destination": "lib/types/popper_v1/"
    }
    
    是的。。。我的
    “destination”
    属性是“popper\u v1”

    它的名字不对。
    import*作为“Popper.js”中的Popper
    找不到此目录。 需要将目录名修改为“lib/types/popper.js”


    [如何修复] 我找到了两只小燕鸥要修理

  • 将设置tsconfig.json更改为编译器可以搜索“lib”目录
  • 通过Libman将库的目录名更改为“node_modules”(不推荐)
  • 我建议使用1。因为我们使用Libman,而不是Node。 如果我们看到“node_modules”目录,就会产生一种误解,认为我们正在使用node

    但是,通过更改为“node_modules”,可以使整体配置看起来更简单


    1.将设置tsconfig.json更改为编译器可以搜索“lib”目录。
    2.通过Libman将库的目录名更改为“node_modules”(不推荐)。

    是否尝试移动库顶部的
    popper
    项?我更改了libman.json顺序,但不幸的是,它没有解决错误。
    {
      "compilerOptions": {
        "noImplicitAny": false,
        "noEmitOnError": true,
        "removeComments": false,
        "sourceMap": true,
        "target": "es5",
        "lib": [ "ES6", "DOM" ],
        "baseUrl": ".",
        "typeRoots": [
          "./lib/types"
        ]
      },
      "exclude": [
        "node_modules",
        "wwwroot",
        "lib"
      ]
    }
    
    {
      "provider": "filesystem",
      "library": "lib_ManualInstallSources/popper_v1/",
      "destination": "lib/types/popper_v1/"
    }
    
    // tsconfig.json
    {
      "compilerOptions": {
        "sourceMap": true,
        "target": "es5",
        "lib": [ "ES6", "DOM" ],
        "baseUrl": ".",
        "typeRoots": [
          "./node_modules/@types", // Default path to search typings.
          "./lib/types"            // Directory of typings that located by Libman.
        ],
        "paths": {
          // If absolute module name provided on .ts/.d.ts files, compiler will check "./lib/moduleName", "./lib/types/moduleName".
          // e.g. 'import * as Popper from "popper.js"' is convert to "./lib/popper.js" and "./lib/types/popper.js".
          //      Then "./lib/types/popper.js" is correctly path. Error fixed.
          "*": [ "lib/*", "lib/types/*" ]
        }
      },
      "exclude": [
        "node_modules",
        "wwwroot",
        "lib"
      ]
    }
    
    // libman.json
    {
      "version": "1.0",
      "defaultProvider": "jsDelivr",
      "libraries": [
        {
          "provider": "cdnjs",
          "library": "popper.js@1.16.1",
          "destination": "lib/popper.js/"
        },
        {
          "provider": "filesystem",
          "library": "lib_ManualInstallSources/popper_v1/",
          "destination": "lib/types/popper.js/"
        },
        {
          "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/"
        }
      ]
    }
    
    {
      "compilerOptions": {
        "sourceMap": true,
        "target": "es5",
        "lib": [ "ES6", "DOM" ],
        "baseUrl": "."
      },
      "exclude": [
        "node_modules",
        "wwwroot",
        "lib"
      ]
    }
    
    {
      "version": "1.0",
      "defaultProvider": "jsDelivr",
      "libraries": [
        {
          "provider": "cdnjs",
          "library": "popper.js@1.16.1",
          "destination": "node_modules/popper.js/"
        },
        {
          "provider": "filesystem",
          "library": "lib_ManualInstallSources/popper_v1/",
          "destination": "node_modules/types/popper.js/"
        },
        {
          "library": "bootstrap@4.5.2",
          "destination": "node_modules/bootstrap/"
        },
        {
          "library": "@types/bootstrap@4.5.0",
          "destination": "node_modules/types/bootstrap/"
        },
        {
          "library": "jquery@3.5.1",
          "destination": "node_modules/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": "node_modules/types/jquery/"
        },
        {
          "library": "@types/sizzle@2.3.2",
          "destination": "node_modules/types/sizzle/"
        }
      ]
    }