代码之家  ›  专栏  ›  技术社区  ›  Vladimir Venegas

typescript包与npm一起正确安装,但vs代码找不到它

  •  0
  • Vladimir Venegas  · 技术社区  · 8 年前

    我正在用typescript开发一个非常简单的npm包(类型异常)。我的测试运行时没有错误,我可以在npm上发布,甚至可以将其安装到另一个项目(项目b)中;但是当我将其作为引用导入时,vs code抛出一个异常“找不到'type exception'模块”(在项目b上)。

    我已经在项目b上安装了另一个包,没有错误,所以我认为我在npm上发布的包有一些问题,但是我不知道是什么。

    基本上,我创建了两个类,并在main.ts文件中按如下方式导出它们:

    export { nameof } from "./reflection-helper";
    export { TypeException } from "./type-exception";
    

    异常项目类型的“我的文件夹”项目结构如下:

    src
    +-src
    |--index.ts
    |--reflection-helper.ts
    |--type-exception.ts
    |-test
    |-node_modules
    +-lib
    |--src
    |--test
    

    可以找到“类型异常”项目的源代码 here

    1 回复  |  直到 8 年前
        1
  •  2
  •   basarat    8 年前

    抛出异常“找不到'type exception'模块”(在项目b上)

    这是运行时异常。这是因为你的项目 main 未指向文件: https://github.com/vvenegasv/type-exception/blob/f7ec4f63a4cb129e73ed2c4592014adb7b363913/src/package.json#L5

    它是

    "main": "type-exception",
    

    应该像

    "main": "./lib/something/type-exception",
    
    推荐文章