Cannot debug app if using mongodb

debug
nodejs
mongodb

#1

I have a project using express and mongodb.

I have successfully installed mongodb, and I can connect to it. If I run my app, I am able to insert and query the db.
I am able to successfully run my app from a terminal using “node app.js”.

Problem:

When I try to debug my app (running my app from a “Run Configuration”) I get the following error :

ENOTDIR: not a directory, stat ‘/home/ubuntu/workspace/node_modules/mongodb/node_modules/mongodb-core/lib/auth/gssapi.js/package.json’

This is caused by the line of code which is loading the mongodb :

var MongoClient = require(‘mongodb’).MongoClient

What am I doing wrong ? Why does this work if I start the app from a terminal, and not when I start it from a “Run Configuration” ?

( I am really new to C9 and node.js , hopefully I am not doing anything stupid )


#2

There may be something different in environment variables.
start by adding console.log(require.resolve('mongodb')) before the require line, to see if same mongodb is called in both cases.


#3

I tried, but the error occurs before the console.log(require.resolve('mongodb')) gets executed.

So apparently this crashes as soon as I import mongodb. ( But only when debugging )

Any ideas ? Thanks a lot.


#4

console.log(require.resolve('mongodb')) gets executed.
but what does it print?
Also maybe different version of node is used when debugging? Which runner do you use?


#5

Yes, you are right.
For both run types it prints /home/ubuntu/workspace/node_modules/mongodb/index.js

I am ussing the Node.js(default) runner.


#6

Node.js(default) runner uses default version from nvm. Do you use the same when running from commandline?


#7

When running from the commandline I just use node app.js … I assume this uses the default version?

Executing nvm ls prints :

v0.8.28
v0.10.46
v0.12.15
iojs-v3.3.1
-> v4.5.0
v5.12.0
system
default -> 4 (-> v4.5.0)
node -> stable (-> v5.12.0) (default)
stable -> 5.12 (-> v5.12.0) (default)
iojs -> iojs-v3.3 (-> iojs-v3.3.1) (default)

Executing node --versions prints :

v4.5.0


#8

So as I was fearing from the beginning, it was something stupid.

I had “Pause on uncaught exceptions” enabled, and obviously the app was not getting deployed, as the execution was paused at some uncaught exception in fs.js