I am trying to up my local angular dev env using ng serve, it was working perfectly fine a day back, but now every time I run ng serve or npm start it throws an error:
An unhandled exception occurred: Project does not exist.
I have tried running ng serve in one of my different project, it works there.
not sure what it causing this error
This error often occurs when a project you are running is not an Angular project. It may also be the case when you download an Angular project but do not have latest dependencies installed on your machine. Installing latest dependencies should fix the problem.
To Fix Error “This command is not available when running the Angular CLI outside a workspace Error”, Do Right-Click on yours project name in VS Code and Click “Open in Integrated Terminal” Option. It would open the project to your terminal and error would be fixed.
The angular. json file at the root level of an Angular workspace provides workspace-wide and project-specific configuration defaults. These are used for build and development tools provided by the Angular CLI. Path values given in the configuration are relative to the root workspace directory.
Enter the angular cli path in your system. Click on and close all the windows related to the environment variables. Now go to the project folder and run 'ng serve'. Now you can see the application start running.
Make sure the name of the project in your angular.json
matches what is being called from your package.json
scripts section.
This is how I discovered the problem. I was getting the following error:
An unhandled exception occurred: Project does not exist.
See "C:\Users\Adam\AppData\Local\Temp\ng-XcQsPs\angular-errors.log" for further details.
When I went to that log file, I saw this:
[error] Error: Project does not exist.
at WorkspaceNodeModulesArchitectHost.findProjectTarget (C:\Users\Adam\source\repos\TechScore.Express\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:94:23)
at WorkspaceNodeModulesArchitectHost.getBuilderNameForTarget (C:\Users\Adam\source\repos\TechScore.Express\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:13:39)
at RunCommand.runSingleTarget (C:\Users\Adam\source\repos\TechScore.Express\node_modules\@angular\cli\models\architect-command.js:175:55)
at RunCommand.runArchitectTarget (C:\Users\Adam\source\repos\TechScore.Express\node_modules\@angular\cli\models\architect-command.js:218:35)
at RunCommand.run (C:\Users\Adam\source\repos\TechScore.Express\node_modules\@angular\cli\commands\run-impl.js:14:25)
at RunCommand.validateAndRun (C:\Users\Adam\source\repos\TechScore.Express\node_modules\@angular\cli\models\command.js:134:39)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
So I opened node-modules-architect-host.js:94:23
and saw this:
const projectDefinition = this._workspace.projects.get(target.project);
if (!projectDefinition) {
throw new Error('Project does not exist.');
}
I have no idea why they throw an error like this without telling you which project does not exist. So I changed the file to be like this:
throw new Error('Project does not exist. ' + target.project);
Now, when I build, I get an error like this instead:
An unhandled exception occurred: Project does not exist. client-app
Finally I can see who the culprit is! A global search for "client-app" showed me that it was being used from package.json
, but my project in angular.json
was "ClientApp". Changing all references of "ClientApp" to "client-app" fixed the problem for me.
Similar to issue mentioned by adam0101, the issue got fixed for me by changing the project name. Infact package.json and angular.json names can be different( at least for me), but within angular.json, the naming was consistent
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"e-admin": { ======NAME USED HERE=======
"root": "",
...
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "eAdmin:build" ===NAME USED HERE====
},
"configurations": {
"production": {
"browserTarget": "eAdmin:build:production" <===NAME USED HERE
}
}
},
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"e-admin": {
"root": "",
...
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "e-admin:build"
},
"configurations": {
"production": {
"browserTarget": "e-admin:build:production"
}
}
},
please check projects name and defaultProject are same
testapp
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": { // here
"testapp": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
.....................
"defaultProject": "testapp",
please try
npm install
or
yarn install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With