【问题标题】:Error TS6200 & Error TS2403: Definitions of the following identifiers conflict with those in another file错误 TS6200 & 错误 TS2403:以下标识符的定义与另一个文件中的标识符冲突
【发布时间】:2023-03-17 03:30:02
【问题描述】:

我正在尝试在 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, disconnected, connected, connected, disconnecting, uninitialized, Error, 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;
                  ~~~~~~~~~~~



【问题讨论】:

    标签: node.js typescript mongoose


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

        • 谢谢!完美!
        • 谢谢!这个答案让我省了很多!
        猜你喜欢
        • 1970-01-01
        • 2019-08-11
        • 2019-12-16
        • 2014-06-05
        • 2015-05-12
        • 2012-02-26
        • 2011-10-23
        • 1970-01-01
        • 2017-02-22
        相关资源
        最近更新 更多