0
votes

I have a problem trying to run my project on localhost:8080 with reload. So when I try and start my project on localhost it gives me this error:

Deprecation Error

This is not a problem with my project, this exact project was working last week and now none of my projects can run properly. To make sure it wasn't my project I went into the file explorer and opened the index.html file with chrome and it only ran the index.html none of my script being brought in were working. I don't know what to do to fix this. If anyone can help that would be great.

2
I'd look for code that calls an asynchronous function without a callback - if you've made no changes, and haven't updated nodejs, then you shouldn't have any changes in behaviour compared to last week - Jaromanda X
That's not an error, it's a warning. To fix it, don't use code (your own, or in a library), that uses async functions without a callback. - Flimzy
As @Flimzy noted it's a deprecation warning. Most likely your version of node was updated and now it's letting you know that such usage was previously okay but is now discouraged. Recently, I encountered it while writing a quick script that would write to a file. Since I didn't need any callbacks i had to use writeFileSync so that I wouldn't get the error. Just look for similar usages in your code and adjust as necessary. - Christopher
@Christopher I fixed it. I had to uninstall and reinstall nodejs. which was weird because I had node v7.8.0 installed. now I have v6.10.1 . I don't know the difference of the 2 versions. If one of you guys can elaborate on the differences that would be helpful. - Kevorkian
Use nvm or n to switch and install different versions of node. - Denis Tsoi

2 Answers

1
votes

Going back to the previous version works, in the mean time, but will not solve the problem in the long run, and you'll not get the benefits of new fixes, updates, and upgrades.

One example that would cause that warning when called is the function

fs.readFile(path[, options], callback)

Without the callback, the warning would appear.

To prevent the warning and implement the callback would be like for example:

const fs = require('fs');
fs.readFile('./good.txt', 'utf8', function read(err, data) {
        if (err) {
            throw err;
        }
        content = data;
        // call the next step here
        console.log(content); // content display
    it
    });

the callback function read(), does two things,

  1. it gets the content of the data based on the encoding, in this example specified as utf8.
  2. And then capture and throw the error(err) if there is any.

Note: encoding is necessary, if you want the file to be human-readable

0
votes

I had node v7.8.0 installed which was causing me problems. I uninstalled that version and installed node v6.10.1 which fixed this weird issue.