【问题标题】:Module '"mongoose"' has no exported member 'CreateQuery'模块“猫鼬”没有导出成员“CreateQuery”
【发布时间】:2021-06-17 20:49:31
【问题描述】:

我正在这样做

import { CreateQuery, FilterQuery, QueryFindBaseOptions } from 'mongoose';

我收到以下错误:

Module '"mongoose"' has no exported member 'CreateQuery'.
Module '"mongoose"' has no exported member 'QueryFindBaseOptions'.

我尝试使用npm i @types/mongoose,但问题没有解决。 我还看到here,自 2021 年 6 月 3 日起不再需要上面的包,因为Mongoose publishes its own types, so you do not need to install this package.

解决这个错误的方法是什么?

【问题讨论】:

  • 我没用过猫鼬,但一定能帮到你。你能告诉 used CreateQuery 在哪里使用吗?我的意思是你在哪里传递这个方法/变量
  • 如果您深入研究源代码,您会发现没有导出CreateQueryQueryFindBaseOptions 。您在哪里可以找到这些变量?
  • @AmirSaleem 和 Cuong,我正在学习本教程:youtu.be/TbT7eO1fxuI?t=599

标签: node.js typescript mongoose


【解决方案1】:

好的,请参考您关注的tutorial,它使用"@types/mongoose": "^5.10.5",并且由于该视频于2021年5月28日发布,因此5.10.5版本将用于@types/mongoose。这就是为什么可以使用CreateQueryQueryFindBaseOptions 的原因。但是@types/mongoose 于 2021 年 3 月 6 日发布了 5.11 版本,因此当您按照教程进行操作时将选择此版本,但版本 5.11 没有导出任何内容。

如果您仍想按照教程进行操作,可以通过在package.json 中指定"@types/mongoose": "5.10.5" 来使用版本5.10.5@types/mongoose

【讨论】:

  • 对于那些想要确切命令的人:npm i @types/mongoose@5.10.5 -D
猜你喜欢
  • 2019-12-29
  • 1970-01-01
  • 2017-05-20
  • 2017-05-07
  • 2017-08-18
  • 1970-01-01
  • 2017-09-09
  • 2022-01-12
相关资源
最近更新 更多