Debug Typescript/Javsacript Mongodb in VS code gives error: ENOTDIR: not a directory, stat

Viewed 695

Mac OS 10.12.6, node from brew v8.5.0, npm v5.3.0 installed with brew, Visual Studio Code v1.16.1, tsc 2.4.1

I am trying to run the following snippet:

import { MongoClient } from 'mongodb';
MongoClient.connect('<url>', (err, db) => console.log(err) );

In bash terminal running the program with node, gives the expected result: null.


But in Visual Studio code, with the following debug configuration:

"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/src/17_Mongo.js"

Gives the following error:

Error: ENOTDIR: not a directory, stat '/Users/alexbjorlig/Documents/SolidFlow/streamRD/node_modules/mongodb-core/index.js/package.json'
at fs.existsSync (fs.js:329:13)
at find_package_json (/Users/alexbjorlig/Documents/SolidFlow/streamRD/node_modules/require_optional/index.js:14:9)
at find_package_json_with_name (/Users/alexbjorlig/Documents/SolidFlow/streamRD/node_modules/require_optional/index.js:34:20)
at require_optional (/Users/alexbjorlig/Documents/SolidFlow/streamRD/node_modules/require_optional/index.js:69:13)
at Object.<anonymous> (/Users/alexbjorlig/Documents/SolidFlow/streamRD/node_modules/mongodb-core/index.js:6:20)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)

To fix the issue I tried:

  • Upgrading node and npm
  • Create package.json from scratch, with mongodb as only dependency

What could I try from here? Possible duplicate of this question, but the suggestions to update did not help me.

edit-1: my package.json file:

"dependencies": {
  "mongodb": "^2.2.31"
}

edit-2: my tscconfig.json:

{
"compileOnSave": true,
"compilerOptions": {
    "target": "es5",
    "lib": [
        "es2016",
        "dom"
    ],
    "module": "commonjs",
    "watch": true,
    "moduleResolution": "node",
    "sourceMap": true
},
"exclude": [
    "node_modules",
    "functions/node_modules",
    "node_modules"
]

}

0 Answers
Related