[英]Error: Cannot find module 'mongodb'
I'm using Visual Studio with node.js tools. 我正在将Visual Studio与node.js工具一起使用。 My project won't start up and it's throwing the error.
我的项目将无法启动,并且会引发错误。
Error: Cannot find module 'mongodb'
This is a package I had previously installed, I figured maybe the global package directory might be a useful place to look, does anyone know where this is located? 这是我以前安装的软件包,我认为全局软件包目录可能是个有用的地方,有人知道它的位置吗?
I've narrowed it down to when I 我把范围缩小到我什么时候
require('mongoose')
I have the mongoose
package, I have mongodb installed (correctly I think, and not the package but the actual thing, this stuff confuses the hell out of me), so not sure why it's complaining. 我有
mongoose
包,我安装了mongodb(我认为是正确的,不是包,而是实际的东西,这些东西使我感到困惑),所以不确定为什么会抱怨。
Quick Fix: 快速解决:
The mongoose package.json
file lists mongodb
as a dependency. mongoose
package.json
文件将mongodb
列为依赖项。 The mongodb
package will be in the mongoose
package's node_modules
directory. 在
mongodb
包装将是mongoose
包的node_modules
目录。 This won't be a global install problem... 这不会是全局安装问题...
The easiest fix to try is to run this in the project's root directory: 尝试进行的最简单的修补是在项目的根目录中运行此命令:
npm install mongoose
If you require a specific version of mongoose
, use this format: 如果您需要特定版本的
mongoose
,请使用以下格式:
npm install mongoose@x.y.z
...where xyz
is the version, like 3.8.8
. ...其中
xyz
是版本,例如3.8.8
。
If the Quick Fix Fails 如果快速修复失败
There's a good chance that the mongodb
build failed during mongoose
installation and will fail again because of an incompatible Windows VisualStudio/SDK version or a missing Python dependency. mongodb
安装很有可能在mongoose
安装期间失败,并且由于不兼容的Windows VisualStudio / SDK版本或缺少Python依赖关系而再次失败。 This is based upon personal experience and from helping other Windows users with npm install failures... 这是基于个人经验以及通过帮助其他Windows用户执行npm安装失败而产生的。
If there are errors on a second try and they are from the mongodb
build, the messages will usually be clear about what dependency isn't being met and what you can install to fix things. 如果有在第二次尝试错误,他们是从
mongodb
构建,消息通常会清楚你可以安装解决的事情依赖没有被满足什么,什么。 If not, you can check the node-gyp dependency requirements and verify you meet those requirements. 如果不是,则可以检查node-gyp依赖项要求并确认您满足这些要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.