Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Set up Debugging with VS Code

I cannot debug because it throws an error

When I try to open debug mode, it starts, and then instantly throws:

Debugger attached.
Waiting for the debugger to disconnect...
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'http-errors'

How can I fix this?

2 Answers

Robert Manolis
STAFF
Robert Manolis
Treehouse Guest Teacher

Hi babyoscar, it looks like you need to install the http-errors module. Kill the app and run npm i http-errors, then start the app again. :thumbsup:

Okay, it works for the http-errors, but why do I have to install each module seperately? I ran "npm install" but after I ran what you said, it said cannot find module express. I did npm i express, then it said cannot find module cookie-parser. Why is that?

Robert Manolis
Robert Manolis
Treehouse Guest Teacher

Hey babyoscar , running npm i will install any dependencies that are already listed in your package.json file. If you have dependencies that are being imported in your project files but aren't listed in the package.json file and haven't been installed, then they will need to be installed individually.

My package.json looks like:

{
  "name": "debug-node-with-vs-code",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "start": "nodemon ./bin/www"
  },
  "dependencies": {
    "cookie-parser": "~1.4.4",
    "debug": "~2.6.9",
    "express": "^4.16.4",
    "http-errors": "~1.6.3",
    "morgan": "~1.9.1",
    "pug": "^2.0.4"
  },
  "devDependencies": {
    "nodemon": "^1.19.1"
  }
}

I ran npm i but it still says Error: cannot find module 'cookie-parser' even though its in my package.json file. Why is that?

Okay, I just installed each one individually, but when I click Run --> Start Debugging --> Node.js (Legacy) , or click the bug with the play button --> run and debug --> Node.js (Legacy), it doesn't create a launch.json file, how do I fix that?

Robert Manolis
Robert Manolis
Treehouse Guest Teacher

Not sure, babyoscar. I don't use the debugger much, and haven't messed with the launch.json file. Try Googling on that, or creating a new post in the community. And make sure your Node and npm are updated to the latest stable version. :thumbsup:

Okay, thanks.

James Fleming
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James Fleming
Full Stack JavaScript Techdegree Graduate 15,848 Points

So I was getting all of these same errors. Every time I would install a module, it would come back and say "cannot find module 'pug' or whatever the module was that it couldn't find. I kept running "npm i " followed by the module it couldn't find and eventually, it worked and the page loaded on the browser. Strange that isn't mentioned in the video but it did work. Hopefully this helps!

Yes, I did that, but it's not creating a launch.json file. I've moved on from this course, but thanks!