错误:找不到模块“mongodb" [英] Error: Cannot find module 'mongodb'
问题描述
我将 Visual Studio 与 node.js 工具一起使用.我的项目无法启动并抛出错误.
错误:找不到模块mongodb"
这是我之前安装的一个包,我想也许全局包目录可能是一个有用的地方,有人知道它在哪里吗?
我已经把范围缩小到当我
require('猫鼬')
我有 mongoose
包,我安装了 mongodb(我认为是正确的,不是包而是实际的东西,这东西让我很困惑),所以不知道为什么会抱怨.
快速修复:
猫鼬 package.json
文件 将 mongodb
列为依赖项.mongodb
包将位于 mongoose
包的 node_modules
目录中.这不会是全局安装问题...
最简单的修复方法是在项目的根目录中运行它:
npm 安装猫鼬
如果您需要特定版本的 mongoose
,请使用以下格式:
npm install mongoose@x.y.z
...其中 x.y.z
是版本,例如 3.8.8
.
如果快速修复失败
mongodb
构建很可能在 mongoose
安装期间失败,并且由于 Windows VisualStudio/SDK 版本不兼容或缺少 Python 依赖项而再次失败.这是基于个人经验和帮助其他 Windows 用户解决 npm 安装失败...
如果第二次尝试出现错误并且它们来自 mongodb
构建,则消息通常会明确说明未满足哪些依赖项以及您可以安装来修理东西.如果没有,您可以查看 node-gyp 依赖项要求并验证您是否满足这些要求.>
I'm using Visual Studio with node.js tools. 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.
Quick Fix:
The mongoose package.json
file lists mongodb
as a dependency. The mongodb
package will be in the mongoose
package's node_modules
directory. 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:
npm install mongoose@x.y.z
...where x.y.z
is the version, like 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. This is based upon personal experience and from helping other Windows users with npm install failures...
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. If not, you can check the node-gyp dependency requirements and verify you meet those requirements.
这篇关于错误:找不到模块“mongodb"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!