【问题标题】:error TS6200 error: Definitions of the following identifiers conflict with those in another fileerror TS6200 错误:以下标识符的定义与另一个文件中的标识符冲突
【发布时间】:2022-01-17 11:51:35
【问题描述】:

我的项目中出现此错误。请帮忙:(

node_modules/mongoose/index.d.ts:1:1 - 错误 TS6200:以下标识符的定义与另一个文件中的标识符冲突:NativeDate、NativeError、Mongoose、SchemaTypes、STATES、connection、mongo、version、CastError、集合、连接、错误、QueryCursor、VirtualType、架构、SchemaDefinition、子文档、数组、DocumentArray、缓冲区、ObjectId、Decimal128、查询、mquery、聚合、SchemaType、Promise、PromiseProvider、模型

1 声明模块“猫鼬”{

node_modules/@types/mongoose/index.d.ts:80:1 80 声明模块“猫鼬”{ ~~~~~~~

此文件中存在冲突。 node_modules/mongoose/index.d.ts:1143:5 - 错误 TS2374:“字符串”类型的索引签名重复。

1143 [k: 字符串]: 字符串;

// package.json

{
  "name": "whatsapp-bot",
  "version": "1.0.0",
  "description": "Whatsapp Bot",
  "main": "build/index.js",
  "scripts": {
    "compile": "tsc && node build/index.js",
    "dev": "NODE_ENV=dev nodemon -e ts --exec \"npm run compile\"",
    "start": "NODE_ENV=prod node build/index.js",
    "lint": "eslint . --ext .ts"
  },
  "repository": "https://github.com/m3rashid/whatsapp-bot.git",
  "author": "MD Rashid Hussain <mdrashid.hussain.786.01@gmail.com>",
  "license": "MIT",
  "devDependencies": {
    "@types/mongoose-auto-increment": "^5.0.34",
    "@types/node": "16",
    "@types/pdfkit": "^0.12.3",
    "@typescript-eslint/eslint-plugin": "^5.9.1",
    "@typescript-eslint/parser": "^5.9.1",
    "eslint": "^8.6.0",
    "nodemon": "^2.0.15",
    "typescript": "^4.5.4"
  },
  "dependencies": {
    "dotenv": "^11.0.0",
    "mongoose": "^6.1.6",
    "mongoose-auto-increment": "^5.0.1",
    "pdfkit": "^0.13.0",
    "venom-bot": "^4.0.4"
  }
}
// how i am making schemas/models

import mongoose from "mongoose";

interface LinkDocument extends mongoose.Document {
  url: string;
  title: string;
  description: string;
  imageUrl: string;
}

const linkSchema = new mongoose.Schema({
  url: String,
  title: String,
  description: String,
  imageUrl: String,
});

const Link = mongoose.model<LinkDocument>("Link", linkSchema);
export default Link;

我想将"skipLibCheck": true 添加到我的tsconfig.json,但后来我在 venom.create() 函数中遇到了其他错误TypeError: Cannot read properties of undefined (reading 'create')

另外,这样,我失去了严格的类型检查,我该怎么办?

【问题讨论】:

    标签: node.js typescript mongodb mongoose


    【解决方案1】:

    使用 Yarn 2 或 Yarn 3 (Yarn "Berry") 和工作区时似乎会发生此错误。 Yarn 为工作区创建硬链接,TS 无法正确处理。

    有关详细信息,请参阅 https://github.com/Microsoft/TypeScript/issues/14565#issuecomment-1014112024https://github.com/microsoft/TypeScript/issues/36294


    旧帖:

    您是否有机会使用新的 Visual Studio 2022 .esproj 项目类型?我们刚刚从 VS2019 迁移到 VS2022,从 .njsproj 迁移到 .esproj,这些错误开始出现。

    (对不起,我会发表评论,但我没有足够的声誉)

    【讨论】:

    猜你喜欢
    • 2023-03-17
    • 2019-08-11
    • 2019-12-16
    • 1970-01-01
    • 2014-06-05
    • 2015-05-12
    • 2012-02-26
    • 2011-10-23
    • 1970-01-01
    相关资源
    最近更新 更多