Skip to content

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

Closed

Description

@laggage

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_

Activity

  1. alan-agius4 commented on Sep 2, 2022

    @alan-agius4
    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.

  2. added
    freq1: low
    on Sep 2, 2022
  3. self-assigned this
    on Sep 2, 2022
  4. laggage commented on Sep 2, 2022

    @laggage
    Author

    @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

  5. alan-agius4 commented on Sep 2, 2022

    @alan-agius4
    Collaborator

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

  6. added a commit that references this issue on Sep 2, 2022
    2632991
  7. laggage commented on Sep 2, 2022

    @laggage
    Author

    @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"
            }
        }
    }
    
  8. alan-agius4 commented on Sep 2, 2022

    @alan-agius4
    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": "",
  9. laggage commented on Sep 2, 2022

    @laggage
    Author

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

  10. added a commit that references this issue on Sep 2, 2022
    57d93fb
  11. angular-automatic-lock-bot commented on Oct 3, 2022

    @angular-automatic-lock-bot

    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.

  12. locked and limited conversation to collaborators on Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: @schematics/angularfreq1: lowseverity1: confusingtype: bug/fix

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions