[英]Node Error: Cannot find module - typescript api for custom module where I export mongoose schemas and interfaces
I have a typescript module @tlabs/models where I'm simply exporting in index.ts: 我有一个打字稿模块@ tlabs / models ,在这里我只是在index.ts中导出:
export * from '../models......'
where in each file I have something like: 在每个文件中,我都有以下内容:
export const Project = typedModel('projects', ProjectSchema);
and my only dependency is ts-mongoose
imported in each file simply as: 我唯一的依赖项是在每个文件中简单地导入
ts-mongoose
,如下所示:
import { createSchema, Type, typedModel, ExtractProps } from 'ts-mongoose';
ts-mongoose being a dependency that itself required mongoose + mongoose types. ts-mongoose是一个依赖项,它本身需要mongoose + mongoose类型。
In my typescript node project I have ts-mongoose
, mongoose
and @tlabs/models as dependencies and @types/mongoose
as dev dependency. 在我的打字稿节点的项目,我有
ts-mongoose
, mongoose
和@ tlabs /模型作为依赖和@types/mongoose
的开发依赖。
Running tsc is fine, the files get compiled and there's no error being thrown out but then trying to run the actual files throws out: 运行tsc很好,文件被编译并且没有错误被抛出,但是随后尝试运行实际文件被抛出:
Error: Cannot find module '@tlabs/models'
I have reinstalled all modules several times and checked package.json as well as the actual files on the disk + through vscode and they're right there. 我已经重新安装了所有模块几次,并通过vscode检查了package.json以及磁盘上的实际文件,它们就在那里。
What am I missing out? 我错过了什么?
My tsconfig is: 我的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
}
}
My final TS config for my exported models: 我导出的模型的最终TS配置:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "lib",
"strict": true,
"esModuleInterop": true
},
"include": ["src"]
}
and relevant package.json configuration: 和相关的package.json配置:
{
"main": "lib/index.js",
"types": "lib",
"scripts": {
"tsc": "tsc",
"build": "tsc -p ."
},
"files": [
"lib"
],
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.