Skip to content

ng g component <ComponentName> Failed with error "Project "undefined" does not exist." #23848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
laggage opened this issue Sep 2, 2022 · 7 comments · Fixed by #23850
Closed
1 task done
Assignees
Labels
area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity1: confusing type: bug/fix

Comments

@laggage
Copy link

laggage commented Sep 2, 2022

Command

generate

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

After updated to angular14, the defaultProjectproperty in angular.json was removed after run ng update, however, when i
try to create an component with ng g component command, it failed with "Project "undefined" does not exist." error, if i add defaultProject back to angular.json, the command will success, but a warning appeared in the console output "DEPRECATED: The 'defaultProject' workspace option has been deprecated. The project to use will be determined from the current working directory."

Minimal Reproduction

  • run ng g component <componentName>

Exception or Error

No response

Your Environment

✗ npm run ng -- version

> [email protected] ng
> ng version


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 14.2.1
Node: 16.13.1
Package Manager: npm 8.19.0 
OS: darwin x64

Angular: 14.2.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router, service-worker


### Anything else relevant?

_No response_
@alan-agius4
Copy link
Collaborator

The root problem here is that a project cannot be determined. You can either change the current working directory using (cd) or provide the name of the project using the --project option.

We should update the error message to be more actionable.

@alan-agius4 alan-agius4 added type: bug/fix severity1: confusing freq1: low Only reported by a handful of users who observe it rarely area: @schematics/angular labels Sep 2, 2022
@alan-agius4 alan-agius4 self-assigned this Sep 2, 2022
@laggage
Copy link
Author

laggage commented Sep 2, 2022

@alan-agius4

This error occurs even when i executed ng g component in the root directory of the project. I have no idea how the cli determine the current project, but i don't think is only things about the error message

image

@alan-agius4
Copy link
Collaborator

Can you please share you angular.json? You can option the architect sections if you'd like.

alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Sep 2, 2022
While this option is always required it was not marked as such

Closes angular#23848
@laggage
Copy link
Author

laggage commented Sep 2, 2022

@alan-agius4 You can see my angular.json below

angular.json
{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
        "blog-admin": {
            "projectType": "application",
            "root": "",
            "sourceRoot": "src",
            "architect": {...},
    },
        "blog-admin-e2e": {
            "root": "",
            "sourceRoot": "",
            "projectType": "application",
            "architect": {
                "e2e": {
                    "builder": "@angular-devkit/build-angular:protractor",
                    "options": {
                        "protractorConfig": "./protractor.conf.js",
                        "devServerTarget": "blog-admin:serve"
                    },
                    "configurations": {
                        "ci": {
                            "protractorConfig": "./protractor.ci.conf.js"
                        }
                    }
                },
                "lint": {
                    "builder": "@angular-eslint/builder:lint",
                    "options": {
                        "lintFilePatterns": ["e2e/**/*.ts"]
                    }
                }
            }
        }
    },
    "schematics": {
        "@schematics/angular:component": {
            "prefix": "cnb",
            "style": "less"
        },
        "@schematics/angular:directive": {
            "prefix": "cnb"
        }
    }
}

@alan-agius4
Copy link
Collaborator

The problem here is that your projects are misconfigured in the angular.json. You have two projects in the same directory as the root is configured the same, as such the CLI cannot determine which project you intend to use.

     "blog-admin": {
            "projectType": "application",
            "root": "",
            "sourceRoot": "src",
    },
    "blog-admin-e2e": {
         "root": "",
         "sourceRoot": "",

@laggage
Copy link
Author

laggage commented Sep 2, 2022

After I changed blog-admin-e2e.root to e2e, things worked, thanks for help

clydin pushed a commit that referenced this issue Sep 2, 2022
While this option is always required it was not marked as such

Closes #23848
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity1: confusing type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants