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 Asynchronous Programming with JavaScript Understanding Promises Create a Promise

keep getting throw error in console..

Hi there, I keep getting a throw error - "Cannot find module...." Here is my link: https://w.trhou.se/6zjjswjbbx Thanks in advance!

3 Answers

Steven Parker
Steven Parker
231,060 Points

The workspace appeared to be set up for use as a server with the Workspace Preview button. But now that you said you are working with node.js, the issue is from running node at the root level, but the program is located in the "js" directory. Start it this way instead (after fixing the space of course):

node js/promises-breakfast.js

Thank you! It finally worked! I just didn't know there was any difference when using the server as the Workspace Preview.

Steven Parker
Steven Parker
231,060 Points

I didn't see the error you mentioned when I tried your snapshot, but I noticed how the data for one person was not available. If that's the same issue, it's because for that person (Sergey Korsakov) you get a disambiguation page instead of the info page the code is expecting. This is because there are two people with similar names in the database.

Adding code to detect and resolve a disambiguation page in a generic way would be a rather advanced challenge. But as a quick fix, you could just check for "Sergey Korsakov" and substitute "Sergey Korsakov (cosmonaut)":

btn.addEventListener('click', () => {
    getJSON(astrosUrl,(json) => {
    json.people.map( person => {
        if (person.name == "Sergey Korsakov")  // change ambiguous name to specific one
            getJSON(wikiUrl + "Sergey Korsakov (cosmonaut)", generateHTML);
        else
            getJSON(wikiUrl + person.name, generateHTML);
    });
});

Hi Steven, Thank you for the swift reply and sorry about the confusion. I should have described it better in my question. Currently, I have moved on from the Callbacks exercise to the Promises exercise.

The issue I was referring to is that when I tried to create a new Promise for my promises-breakfast.js file and run it on the command, it gives me a 'throw' error. Below is a new snapshot I took. Do you get the same error? https://w.trhou.se/p2ovq03goq

Steven Parker
Steven Parker
231,060 Points

I'm still not sure what steps to take to see this error (or what you mean by "run it on the command"), but just looking at the file I notice a stray space that is preventing the arrow operator from being recognised:

setTimeout(() = > {   // operator must be =>
//             ^
//             stray space

Hi Steven, thank you for your effort to help me. Even after I remove the stray space. Basically, I'm seeing this error:

treehouse:~/workspace$ node promises-breakfast.js                          
module.js:550                                                              
    throw err;                                                             
    ^                                                                      

Error: Cannot find module '/home/treehouse/workspace/promises-breakfast.js'
    at Function.Module._resolveFilename (module.js:548:15)                 
    at Function.Module._load (module.js:475:25)                            
    at Function.Module.runMain (module.js:694:10)                          
    at startup (bootstrap_node.js:204:16)                                  
    at bootstrap_node.js:625:3  

I have been stuck on this exercise for awhile. I think I will just move forward. Thank you though.