angular ng serve command throws error: An unhandled exception occurred: Project does not exist
Asked Answered
B

14

44

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

Briefing answered 21/8, 2019 at 6:40 Comment(3)
are you executing ng serve from the correct directory?Crosswalk
update or reinstall angular cliHolbrook
I have the exact same error and updating or reinstalling doesn't help for either angular/cli nor angular itselfJudsonjudus
I
95

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.

Infect answered 25/8, 2019 at 17:41 Comment(6)
There should have added this little piece ('Project does not exist. ' + target.project); there which saves a lot of time.Rhine
This is a great solution and explanation! ThanksRiffraff
When I update my node-modules-architect-host.js file as to your suggestions, I don't even get the new Error message? Any Idea how that could happen?Oberg
@dfbenny, I would double-check that the correct file was modified, that the file was not overwritten by the old version after you modified it, and that a cached version was not being used (maybe clear package cache?).Infect
Name of the project is now included in angular-devkit-architect-builds since august 2020.Misti
I tried this but the error changed to "Project target does not exist".Cockspur
A
20

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

Old

  "$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
            }
          }
        },

Modified

 "$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"
            }
          }
        },
Amylose answered 7/3, 2020 at 10:44 Comment(2)
Thank you, your answer helps me not to waste my time,Fulgurating
Agree, names can be different. In fact, you might have a command defined in angular.json, but even not existing in package.json and it'll still work.Ddt
P
9

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
Polacre answered 24/8, 2020 at 7:12 Comment(0)
D
7

Make sure you angular.json have this config

{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": { // here 
        "testapp": {
            "root": "",
            "sourceRoot": "src",
            "projectType": "application",
Dube answered 21/8, 2019 at 11:9 Comment(1)
this application contain custom ng library I am building from,Briefing
R
6

I match the values in angular.json & package.json and my problem was solved

angular.json:

"projects": {
    "step1": {
      "projectType": "application",
      ...,
      ...,

package.json

{
  "name": "step1",
  ...,
  ...,
Reconcile answered 29/3, 2020 at 17:22 Comment(1)
tried it but error still project "app" does not exist where I have change the name to something else than not "app"Cockspur
S
5

I fixed this issue changing the target in tsconfig.json from es2015 to es5

Spence answered 25/12, 2019 at 14:54 Comment(1)
if you're getting reported issue suddenly without adding or removing any module..... this method will work thumbs up!Steinbach
G
2

@adam0101 The solution helped a lot! Thank you!!!

But I had to add a console.log(target):

const projectDefinition = this._workspace.projects.get(target.project);
if (!projectDefinition) {
    console.log(target)
    throw new Error('Project does not exist.');
}

And I found in the package.json the wrong project name over a global search:

The failure:

Grotto answered 8/4, 2020 at 17:43 Comment(0)
C
2

Project name in angular.json must be the same at every property where is needed.

And take good care of letter case, even in paths, at angular.json.

Windows doesn't complain, but Angular does!!

Carothers answered 21/4, 2020 at 22:26 Comment(0)
H
2

I had the same problem with Angular Universal. For me it was the simplest thing. It is npm run dev:ssr not ng run dev:ssr. However, it is ng run myproject:serve-ssr. Watch for differences between ng and npm.

Heller answered 25/4, 2020 at 7:3 Comment(0)
M
2

I duplicated a project and changed its name getting me this error. Fixed it by changing the project name everywhere else in angular.json.

For example


    "e2e": {
              "builder": "@angular-devkit/build-angular:protractor",
              "options": {
                "protractorConfig": "e2e/protractor.conf.js",
                "devServerTarget": "YourNewProjectName:serve"
              },
              "configurations": {
                "production": {
                  "devServerTarget": "YourNewProjectName:serve:production"
                }
              }
            },

Margo answered 6/4, 2021 at 8:54 Comment(0)
R
1

For anyone still having this issue. It's likely you didn't run npm install or yarn before calling the run script.

Rainbolt answered 18/11, 2019 at 10:40 Comment(0)
D
1

If you are working on an existing project, you might need want to check the codeCoverageExclude inside angular.json and see if your *.spec.ts files are defined inside the array.

You might find your files excluded on the test.

Dicker answered 27/7, 2021 at 2:25 Comment(0)
I
0

For me it only works using

npm run cordova:run android
Inexpressible answered 18/10, 2020 at 22:9 Comment(0)
G
0

Make sure the path of "styles" in the angular.json should be

"./node_modules/bootstrap/dist/css/bootstrap.min.css"

instead of

"../node_modules/bootstrap/dist/css/bootstrap.min.css"

And also remove one dot from the "scripts"

 "scripts": [
              "./node_modules/bootstrap/dist/js/bootstrap.min.js"
            ]
Geordie answered 21/3, 2021 at 16:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.