Angular CLI not recognizing code changes


I’m trying to resolve an issue. I have an angular application that attempts to log to a MongoDB database. It is failing to connect. It prints out “Connection failed!” to the console:

mongoose.connect(/*** DB connection string ***/)
.then(() => {
console.log(“Connected to database!”);
.catch(() => {
console.log(“Connection failed!”); // <-- This prints out

Now I want to print out a few more console messages, something like this:

.catch((err) => {
console.log(“Connection failed!”); // <-- This prints out

But err won’t print.

I change the “connection failed” message to have three exclamations: !!!

console.log(“Connection failed!!!”);

But it still prints “Connection failed!”

It seems like some kind of caching in the CLI.

I have two CLIs (just regular command windows). In one, I run the server for the front end with “ng serve”. In the other, I run the backend with “node server.js”. I stop the one running “node server.js” and start it again, hoping that will recompile the code or clear the cache. It doesn’t work. I stop both servers, close and reopen both CLIs, and start the servers again. Still no go.

One warning I get with the CLI running “ng serve” is “Your global Angular CLI version (6.1.1) is greater than your local version (6.0.8). The local Angular CLI version is used.” I also did some googling to find that the version of Angular CLI can have this effect. But I tried “npm install @angular/cli@6.1.1” to no effect.

I can’t work with my application if it’s not going to update in the CLI. How do I fix this problem? Thanks.

It seems like you are describing two problems here. The first being a javascript/typescript issue and the other a CLI issue. I’m going to try and answer the first.

It seems in this article that the catch is not required, the second function inside the ‘then’ is actually the error handler although I have not tried to recreate your issue so I can’t be certain.

Your second issue I would suggest trying the --watch option on ng serve to recompile your code every time it changes on save. Documentation can be found here:

Didn’t work:

ng serve --watch

Try :

sudo ng serve

It works!