2

When requiring d3.js before a module that requires mongo (connect-mongo) I get the following error:

TypeError: Cannot read property 'BSON' of undefined
    at .../node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/index.js:48:44

If I require d3.js after the mongo module it works fine...

I'm not the first to run into this issue, but I can't figure out whats conflicting How to use D3 in Node.js properly?

Community
  • 1
  • 1
enjalot
  • 660
  • 3
  • 7

1 Answers1

2

This is happening because the version of BSON you're using checks for the existence of a window global to see whether or not it's running in Node.JS. This is a bad idea, e.g. D3.js creates such a global via JSDOM, thus invalidating the check.

However, it looks like this issue has been fixed in a recent commit, i.e. in BSON v0.1.5.

At the time of writing, the version of mongodb on npmjs.org is v1.1.11, but the BSON dependency has been updated in v1.2.0, which appears to be on the verge of being released (see GitHub).

Jason Davies
  • 4,693
  • 30
  • 39