【问题标题】:npm publishing index.d.ts not export modulenpm 发布 index.d.ts 不导出模块
【发布时间】:2016-12-06 22:19:39
【问题描述】:

我们正在尝试创建一个 npm 包,这是我们大多数项目的基础, 但我们遇到以下问题:

我们的基础 npm 包的 index.d.ts 如下所示:

export * from './src/core';

declare module '*.html' {
    const template: string;
    export default template;
}

顶行很好,我们可以访问核心文件夹中的模块, 但是第二部分不起作用。

但是如果我们在自己的项目中将相同的代码放在custom.d.ts 中,那么 html 文件的导入效果很好。

package.json(删除了某些部分)如下所示:

{
  "version": "0.0.0",
  "license": "ISC",
  "main": "dist/main.bundle.js",
  "module": "./index.js",
  "types": "./index.d.ts",
  "engines": {
    "node": ">= 6.0.0",
    "npm": ">= 3"
  }
}

文件夹结构:

app/
├── node_modules/
|   └── base/
│       ├── src/
│       |   └── core/
│       |       └── ....
│       └── index.d.ts
├── src/
│   └── ...
└── custom.d.ts

【问题讨论】:

    标签: node.js typescript npm publishing npm-publish


    【解决方案1】:

    您需要在项目的入口文件中import "base"。 否则 TypeScript 可能不会自动包含 node_modules 下的文件。

    【讨论】:

    • 它是在我们的 vendor.ts 中导入的 :)
    猜你喜欢
    • 2021-08-04
    • 2017-05-13
    • 1970-01-01
    • 2020-02-23
    • 2018-12-07
    • 2020-05-26
    • 2020-01-18
    • 2017-01-09
    • 2022-12-16
    相关资源
    最近更新 更多