MongoDB NodeJS驱动程序的浏览器ify兼容性(调试帮助) [英] MongoDB NodeJS driver's browserify compatibility (debugging help)

查看:93
本文介绍了MongoDB NodeJS驱动程序的浏览器ify兼容性(调试帮助)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图找出我无法通过浏览器识别mongodb本机nodejs驱动程序的问题.我假设我的设置中存在问题,因为我尝试使用Google搜索时是否发现MongoDB NodeJS驱动程序和browserify当前存在任何兼容性问题,但经过几天的尝试,没有任何结论性的结论;(

在browserify上运行代码后,我得到一个

TypeError: require(...).native is not a function

我在驱动程序的github存储库上读到,该驱动程序依赖于某些本机功能以及kerberos和node-gyp.我在机器上安装了驱动程序,而npm install mongodb --save则没有任何问题,所以我不知道是否可能是这种情况.

我用尽了调试的想法,所以我转向了有福的SO社区 :)

我正在使用无服务器框架开发AWS Lambda(因此,我担心驱动程序是否实际上将在Lambda实例上运行,因为该驱动程序需要某些本机功能...).这是我的测试代码

var MongoClient = require('mongodb').MongoClient;
var x = "Hello NodeJS";

console.log(x);

MongoClient.connect("mongodb://localhost:27017/test", (err, db) => {
  console.log("Error null? " + (err == null ? "YES" : "NO"));
  console.log("DB null? " + (db == null ? "YES" : "NO"));
});

我使用了一些ES6语法,例如import和let bc,在我的原始代码中,我也使用babelify对其进行了转换,但是将其删除了,因此仅浏览器会产生一些问题.

我跑起来像

browserify simple.js -o browserified.js

如果有人可以阐明这一点,我将不胜感激.

谢谢

解决方案

我在MongoDB JIRA服务器上创建了一个问题,并确认今天的驱动程序未在浏览器中运行.当然,我不是试图在浏览器中运行它,而是在Node中运行它,但是正如我的朋友@dvlsg在我的问题的评论中指出的那样,browserify可能会填充一些对正确实现MongoDB驱动程序很重要的东西.因此,如果从今天起您不在现场,请尝试一种不包括将mongodb驱动程序与browserify捆绑在一起的解决方法.

驱动程序维护人员确认他正在开发一个将在浏览器中运行的版本,该版本可能会按我需要的方式运行,但即使是alpha发行版也尚未准备好,希望将来您能读到它.

Trying to figure out what's the problem that I can't browserify mongodb native nodejs driver. I'm assuming there is something wrong here in my setup as I tried googling if there was any known current compatibility problem with MongoDB NodeJS driver and browserify but nothing conclusive came up after couple days trying ;(

After running my code on browserify I get a

TypeError: require(...).native is not a function

I read on the driver's github repo that this driver depends on some native functionality and on kerberos and node-gyp. I installed the driver on my machine without any problem with npm install mongodb --save so I don't know if that might be the case.

I ran out of debugging ideas, so I'm turning to the blessed SO community :)

I'm developing for AWS Lambda using the Serverless Framework (so I'm concerned if the driver will actually run on a Lambda instance as the driver requires some native functionality...). Here is my testing code

var MongoClient = require('mongodb').MongoClient;
var x = "Hello NodeJS";

console.log(x);

MongoClient.connect("mongodb://localhost:27017/test", (err, db) => {
  console.log("Error null? " + (err == null ? "YES" : "NO"));
  console.log("DB null? " + (db == null ? "YES" : "NO"));
});

I was using some ES6 syntax like import and let bc in my original code I also transform it with babelify but removed, so just plain browserify creates some problem

I ran it like

browserify simple.js -o browserified.js

If someone can shed a light on this, I'd appreciate.

Thanks

解决方案

I created an issue at MongoDB JIRA server and I was confirmed the driver as of today doesn't run in the browser. Of course, I was not trying to run it in the browser, but in Node, but as my friend @dvlsg pointed in the comments of my question it is possible browserify shims some stuff important for the correct implementation of MongoDB driver. So if you're out there pulling your hair off as of today, try a workaround which does not include bundling up mongodb driver with browserify.

The driver maintainer confirmed he was working on a version that will work in the browser, which will possibly work the way I needed but it is not ready even for alpha release, hopefully if you're reading this in the future...

这篇关于MongoDB NodeJS驱动程序的浏览器ify兼容性(调试帮助)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆