Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio code Debugging Node.JS NOENT: no such file or directory when debugging with MongoDB

have a very strange problem. I'm coding a few small Node.JS programs, and debugging them in Visual Studio Code (for Windows). Well, recently I started to get a weird issue when the program hits the line:

const mongodb = require('mongodb') 

no matter what program I use. Actually it doesn't even has to be a complete program. If my file contains only that line, it will fail with the same issue.

I tried uninstalling and re-installing NPM, MongoDB, and also the packages for my solution and nothing works.

Now the weirdest thing is the program works fine when i run it on the command line. It only fails on the Visual Studio Code debugger.

It appears somewhere in the internal libraries to load modules, this path is generated:

[program_location]\node_modules\require_optional<b>\index.js\package.json

which of course doesn't exist an fails because it won't ever find this file (since is not a valid file anyway)

here's the trace:

Error: ENOENT: no such file or directory, stat 'c:\NodeJS\Module03\MongoMigration\node_modules\require_optional\index.js\package.json' at fs.existsSync (fs.js:329:13) at find_package_json (c:\NodeJS\Module03\MongoMigration\node_modules\require_optional\index.js:14:9) at find_package_json_with_name (c:\NodeJS\Module03\MongoMigration\node_modules\require_optional\index.js:34:20) at require_optional (c:\NodeJS\Module03\MongoMigration\node_modules\require_optional\index.js:69:13) at Object. (c:\NodeJS\Module03\MongoMigration\node_modules\mongodb-core\index.js:8:20) at Module._compile (module.js:635:30) at Object.Module._extensions..js (module.js:646:10) at Module.load (module.js:554:32) at tryModuleLoad (module.js:497:12) at Function.Module._load (module.js:489:3)

It must be something wrongly configured on my machine. Just trying to find if there is somebody who has resolved this one or has some ideas.

Thanks!

like image 461
McFloyd Avatar asked Dec 18 '22 00:12

McFloyd


1 Answers

I was having the issue today. I found that you can fix it if you disable break on "All Exceptions"

enter image description here

like image 61
hardkoded Avatar answered Dec 22 '22 00:12

hardkoded