我有一个打字稿模块 @tlabs/型号,我只是在index.ts中导出:
export * from '../models......'
在每个文件中,我有类似的东西:
export const Project = typedModel('projects', ProjectSchema);
,我唯一的依赖性是在每个文件中导入的ts-mongoose
,只是:
import { createSchema, Type, typedModel, ExtractProps } from 'ts-mongoose';
ts-mongoose是一种依赖性,它本身需要mongoose mongoose类型。
在我的打字稿节点项目中,我有 ts-mongoose
, mongoose
和 @tlabs/型号为依赖项,而 @types/mongoose
作为dev依赖关系。
运行tsc很好,文件被编译,没有错误的错误,但是试图运行实际文件抛出:
Error: Cannot find module '@tlabs/models'
我已经多次重新安装了所有模块,并通过VSCODE上的磁盘 上的实际文件,它们就在那里。
我错过了什么?
我的tsconfig是:
{
"include": ["src/**/*"],
"exclude": ["node_modules", "./node_modules", "./node_modules/*"],
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"allowJs": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"noImplicitAny": false,
"alwaysStrict": true,
"strictNullChecks": true,
"types": [],
"lib": [],
"experimentalDecorators": true
}
}
在我的节点项目中使用/导入此的正确方法是什么?
我的最终TS配置:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "lib",
"strict": true,
"esModuleInterop": true
},
"include": ["src"]
}
和相关软件包。json配置:
{
"main": "lib/index.js",
"types": "lib",
"scripts": {
"tsc": "tsc",
"build": "tsc -p ."
},
"files": [
"lib"
],
}