In this post, I’m going to list the most common errors you may encounter while getting started with Angular. For each error, I’m going to explain what it means and how to solve it.
This post is a work in progress and I’m planning to add more errors. If there is an error you encounter often, please let us know by dropping a comment.
Error 1: ‘ng’ is not recognized
When creating a new project with Angular CLI, you may receive the following error:
'ng' is not recognized as an internal or external command.
This error is simply telling you that Angular CLI is either not installed or not added to the PATH. To solve this error, first, make sure you’re running Node 6.9 or higher. A lot of errors can be resolved by simply upgrading your Node to the latest stable version.
Open up the Terminal on macOS/Linux or Command Prompt on Windows and run the following command to find out the version of Node you are running:
If you’re running an earlier version of Node, head over to nodejs.org and download the installer for the latest stable version.
Once you have installed Node 6.9+, you need to install Angular CLI globally:
npm install -g @angular/cli
Note the -g flag here. This tells NPM that you want to install this package globally so you can run it from any folders on your machine.
Error 2: node_modules appears empty
When you run ng serve, you may receive the following error:
node_modules appears empty, you may need to run `npm install`.
Our Angular applications use a bunch of 3rd-party libraries. These libraries are stored in the node_modules folder inside your project folder. When you create a new project using Angular CLI, these third-party libraries should be installed automatically. However, if you’re using a corrupted or a buggy version of Angular CLI, these libraries are not installed. So, you need to manually install them.
To solve this error, run npm install from the project folder. This command will look at package.json in your project folder. This file includes the list of dependencies of your project. NPM will download and store these dependencies in the node_modules folder.
If you found this post helpful, please share it with others.
If there is an error you’d like me to add to this post, please let me know using the comment box below.
Also, if you want to learn Angular properly from basics to the advanced topics, check out my complete Angular course.