With the rapid updates on the JavaScript frameworks and CLIs,
we often come across problems that can cause a project to stop running. In the case
of Angular projects, we can often see this error:
The serve command requires to be run in an
Angular project, but a project definition could not be found.
|
As a result of the JavaScript framework wars, breaking changes are always introduced.
This error usually can be traced back to an update to our
global or local CLI runtime. To check if this is the problem, we need to review the package.json
file. There, we should look for the @angular/cli dependency. This should indicate
the CLI version that was used to create our project. Lets make a note of this value, as we need to use it to
migrate our project later on.
We should now compare to the current CLI runtime by entering
the following command on the terminal window.
ng v
|
The console should display the current CLI version. If the
versions are different, we need to migrate the project to the new CLI version by
running the command below. Note that the
from version parameter should set to the value found for the @angular/cli
setting.
ng update @angular/cli --migrate-only --from=1.6.7
|
We should now take a look at our project and should notice
changes to the CLI dependency version in the package.json file. Also depending
on your CLI version, the .angular-cli.json file is deleted, and a new angular.json
file is created. This is the project file that the new CLI is looking for and thus the source of the error of no project found. By
adding this file, we should be able to be back on track on run our project
again.
We should be able to enter the following command and the project should be loading fine.
ng server
|
Thanks for reading.
0 comments :
Post a Comment
What do you think?