Skip to content
This repository has been archived by the owner on Apr 27, 2018. It is now read-only.

require('mongodb') fails #45

Closed
GIGene opened this issue Dec 11, 2017 · 3 comments
Closed

require('mongodb') fails #45

GIGene opened this issue Dec 11, 2017 · 3 comments

Comments

@GIGene
Copy link

GIGene commented Dec 11, 2017

New to Visual Studio Code, new to Node.js and new to mongodb. I am running OS X 10.12.X

My mongodb is an instance on atlas, so the mongo server is NOT running locally.
node --version is v9.2.1

I can connect to my mongodb using the shell access tool from mongdb. I can connect to my mongodb instance using a PHP script on my computer.

I can invoke my js script via the command-line / node, and it connects to my mongodb instance.

However, when I invoke my js script from inside Code, I get this error as reported in file "fs.fs" and in the function "fs.existsSync":

Exception has occurred: Error
Error: ENOTDIR: not a directory, stat '/Users/gene/MusicDB/node_modules/require_optional/index.js/package.json'
at fs.existsSync (fs.js:346:13)
at find_package_json (/Users/gene/MusicDB/node_modules/require_optional/index.js:14:9)
at find_package_json_with_name (/Users/gene/MusicDB/node_modules/require_optional/index.js:34:20)
at require_optional (/Users/gene/MusicDB/node_modules/require_optional/index.js:69:13)
at Object. (/Users/gene/MusicDB/node_modules/mongodb-core/index.js:8:20)
at Module._compile (module.js:641:30)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)

I am able to connect to a locally-running mysql server from inside Code. I've installed several other npm packages just to see if I could use them, and none of them have had any problems. Only the mongodb package appears to have an issue. I have since removed all references to node and npm and did a fresh install with only "mysql" and "mongodb" being installed by me. Still, no luck.

@GIGene
Copy link
Author

GIGene commented Dec 24, 2017

Looks like the "file" fs.js is built into the VS Code app. That file (as displayed in the VS Code editor) is NOT editable and I could not find it anywhere in my entire file system.

So I edited the files that called it. The following 3 file edits were enough for my JS app to start to run INSIDE VS Code:

node_modules/require_optional/index.js added line 70: return undefined;
node_modules/mongodb-core/lib/auth/gssapi.js commented out lines 29 and 31 (Kerberos authentication for mongo)
node_modules/mongodb-core/lib/auth/sspi.js commented out lines 29 and 31 (Kerberos authentication for mongo)

My js app can not connect to my atlas-based mongodb instance. Once connected, I can add and retrieve data from my instance.

@Claus1
Copy link

Claus1 commented Mar 23, 2018

The same issue on Win 7 with newest VS version 1.21.1

Error: ENOENT: no such file or directory, stat 'c:\MyProjects\adminsema\server\node_modules\require_optional\index.js\package.json'
at fs.existsSync (fs.js:329:13)
at find_package_json (c:\MyProjects\adminsema\server\node_modules\require_optional\index.js:14:9)
at find_package_json_with_name (c:\MyProjects\adminsema\server\node_modules\require_optional\index.js:34:20)
at require_optional (c:\MyProjects\adminsema\server\node_modules\require_optional\index.js:69:13)
at Object. (c:\MyProjects\adminsema\server\node_modules\mongodb-core\index.js:6:20)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)

Can not debug app in VS!

@Claus1
Copy link

Claus1 commented Mar 23, 2018

It seems I found solution :) If uncheck flag All Exception for Breakpoints in Debug tab everything works ok.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants