从打字稿包导入子文件夹?

时间:2021-07-25 03:57:47

标签: node.js typescript

https://github.com/DavidSouther/monots 中,我有一个简单的多项目 Typescript 配置。

common/ 具有库实用程序,并从 src/ 编译为 lib/package.json 是(我相信)设置为将 .js 中的 .d.tslib/ 文件公开给消费者,而 .js 在 commonjs 中。

server/ 是一个消费应用程序,通过 webpack 捆绑的 nodejs 或 (TODO)。与 common/ 类似,它从 src/ 编译为 lib/,虽然没有声明,但仍然在 commonjs 中。

运行(cd common; npx tsc)后,common/lib填写正确。运行 (cd server ; npm install) 后,tsc 失败并显示

src/index.ts:3:24 - error TS2307: Cannot find module 'common/assert' or its corresponding type declarations.

3 import { assert } from "common/assert";
                         ~~~~~~~~~~~~~~~

从节点的模块加载系统,这应该找到 common/lib/assert/index.jscommon/lib/assert/index.d.ts

common/package.jsoncommon/tsconfig.json 的规范配置是什么,以确保任意消费项目能够像对待注册表中的任何其他包一样对待包?

0 个答案:

没有答案