模块“mongoose”没有导出成员“CreateQuery”

Jus*_*ger 1 mongoose node.js typescript

我正在做这个

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

我收到以下错误:

Module '"mongoose"' has no exported member 'CreateQuery'.
Module '"mongoose"' has no exported member 'QueryFindBaseOptions'.
Run Code Online (Sandbox Code Playgroud)

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

修复此错误的解决方案是什么?

Cuo*_*goc 6

好的,请参阅您正在关注的教程,它使用"@types/mongoose": "^5.10.5"并且由于该视频于 28/5/2021 发布,因此该版本5.10.5将用于@types/mongoose. 这就是为什么CreateQuery并且QueryFindBaseOptions可以使用。但已于 03/06/2021@types/mongoose发布版本5.11,因此当您按照教程进行操作时将选择此版本,但版本中没有导出任何内容5.11

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

  • 对于那些想要确切命令的人:`npm i @types/mongoose@5.10.5 -D` (2认同)