错误 TS6200 和错误 TS2403:以下标识符的定义与另一个文件中的定义冲突

ali*_*ana 13 mongoose node.js typescript

我正在尝试在打字稿中设置一个节点项目。

导致错误的两个文件:

  1. node_modules@types\mongoose\index.d.ts
  2. node_modules\mongoose\index.d.ts

[错误][1][1]:https://i.stack.imgur.com/46vDU.jpg

node_modules/@types/mongoose/index.d.ts:79:1 - 错误 TS6200:以下标识符的定义与另一个文件中的标识符冲突:DocumentDefinition、FilterQuery、UpdateQuery、NativeError、Mongoose、CastError、ConnectionOptions、Collection、Connection、断开连接、连接、连接、断开连接、未初始化、错误、QueryCursor、VirtualType、Schema、SchemaTypeOpts、Subdocument、Array、DocumentArray、Buffer、ObjectIdConstructor、Decimal128、Map、Aggregate、SchemaType、Document、ModelUpdateOptions

79 声明模块“猫鼬”{


node_modules/mongoose/index.d.ts:1:1
 1 declare module "mongoose" {
   ~~~~~~~
 Conflicts are in this file.

node_modules/@types/mongoose/index.d.ts:226:14 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'SchemaTypes' must be of type 'typeof Types', but here has type 'typeof Types'.

226   export var SchemaTypes: typeof Schema.Types;
                  ~~~~~~~~~~~



Run Code Online (Sandbox Code Playgroud)

小智 34

Mongoose 包含 TypeScript 类型mongoose@5.11.0,因此您可以删除该包@types/mongoose

来源:https : //developer.mongodb.com/community/forums/t/schema-error-while-running-backend-server-nestjs-angular/12440/3

  • 谢谢你!完美的! (2认同)

Max*_*ola 11

我刚刚遇到了同样的问题,并通过添加"skipLibCheck": true到我的tsconfig.json. 所以我不必降级 Mongoose。


ali*_*ana 1

没关系,我通过运行“npm i mongoose@5.10.19”降级了猫鼬,它起作用了