【问题标题】:error TS2305: Module '"tls"' has no exported member 'TLSSocketOptions'错误 TS2305:模块 '"tls"' 没有导出的成员 'TLSSocketOptions'
【发布时间】:2021-12-20 08:49:17
【问题描述】:

我正在尝试使用 Node.js 项目中的 MongoDB 驱动程序连接到 MongoDB,但在编译时遇到问题,并收到名义错误“node_modules/mongodb/mongodb.ts34.d.ts:31:10 - 错误TS2305:模块 '"tls"' 没有导出的成员 'TLSSocketOptions'。任何有关如何解决这个明显的节点包问题的帮助都会非常有帮助!

当我检查时,它具有 TLSSocketOptions 的 tls 包,并且似乎通过文件末尾的以下内容将其导出

declare module 'node:tls' {
    export * from 'tls';
}

我的 package.json

{
  "main": "wwwroot/index.js",
  "bin": "wwwroot/index.js",
  "scripts": {
    "start": "node ./wwwroot/index.js",
    "dev": "ts-node src/",
    "compile": "npx tsc",
    "postinstall": "npx tsc"
  },
  "engines": {
    "node": "14.18.1"
  },
  "dependencies": {
    "@discordjs/uws": "^10.149.0",
    "discord.js": "^11.4.2",
    "mongodb": "^4.1.4",
    "snoowrap": "^1.23.0"
  },
  "devDependencies": {
    "@types/node": "^11.15.54",
    "pkg": "^4.5.1",
    "ts-node": "^10.4.0",
    "tslint": "^5.16.0",
    "typescript": "^3.9.10"
  }
}

【问题讨论】:

  • 向我们展示您如何在项目中实施tls(导入和删除)
  • 我的项目中根本不使用tls,我认为它只是在mongodb包中

标签: node.js typescript mongodb node-modules


【解决方案1】:

您的@types/node 版本似乎很古老,我猜从那时起就添加了相关导出

【讨论】:

  • 这成功了,谢谢!我没有意识到它是如此古老,但能够使用npm outdated 并且现在获得了过时软件包的完整列表。代码编译运行
猜你喜欢
  • 2017-03-29
  • 2022-01-16
  • 2021-03-25
  • 2020-11-13
  • 2022-01-18
  • 2018-09-04
  • 2017-06-13
  • 2019-11-28
  • 2019-02-02
相关资源
最近更新 更多