Skip to content

Data path "" must have required property 'project'. #25402

Description

@sergey-morenets

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

Hi

We have two projects that use Angular and Angular CLI. After we've upgraded both projects to Angular 16.x we can't use schematics for one of the projects (second project is fine).
We tried to clear node_modules or cache folders but it didn't help.

Minimal Reproduction

Any time we try to use schematics we always receive an error:

ng generate class Test

Exception or Error

Schematic input does not validate against the Schema: {"name":"Test","path":"src/app/model"}
Errors:

  Data path "" must have required property 'project'.

Your Environment

Angular CLI: 16.1.0
Node: 20.3.0 (Unsupported)
Package Manager: yarn 3.5.1
OS: win32 x64

Angular: 16.1.1
... animations, cdk, common, compiler, compiler-cli, core, forms
... google-maps, localize, material, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1601.0
@angular-devkit/build-angular   16.1.0
@angular-devkit/core            16.1.0
@angular-devkit/schematics      16.1.0
@angular/cli                    16.1.0
@schematics/angular             16.1.0
rxjs                            7.8.1
typescript                      5.0.4

Anything else relevant?

No response

Activity

  1. alan-agius4 commented on Jun 22, 2023

    @alan-agius4
    Collaborator

    This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?

    You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

    This might be related to your directory structure so its really important to get an accurate repro to diagnose this.

  2. Michael-7 commented on Jun 23, 2023

    @Michael-7

    Hey guys, I have the same issue here. Don't really understand why you would need to have 'project' in your path.
    My repo looks like this:

    src
        app
            components
            pages
            services
            types
        assets
        environments
    

    Can't do the ng g component languages command for example. Doesn't work in component or in the app folder.

    My env:

    Angular CLI: 16.1.0
    Node: 18.16.0
    Package Manager: npm 9.5.1
    OS: darwin arm64
    
    Angular: 16.1.1
    ... animations, common, compiler, compiler-cli, core, forms
    ... platform-browser, platform-browser-dynamic, router
    
    Package                         Version
    ---------------------------------------------------------
    @angular-devkit/architect       0.1601.0
    @angular-devkit/build-angular   16.1.0
    @angular-devkit/core            16.1.0
    @angular-devkit/schematics      16.1.0
    @angular/cli                    16.1.0
    @schematics/angular             16.1.1
    rxjs                            7.8.1
    typescript                      5.1.3
    

    I think it might have something to do with me adding extra projects - and renaming the current project - in the angular.json file and it now expecting I have a projects folder because before I did that it worked fine.

  3. alan-agius4 commented on Jun 23, 2023

    @alan-agius4
    Collaborator

    @Michael-7, a project is required so that the Angular CLI can determine in which directory to generate the files. The project value however is provided automatically. I am not sure why in this case it is not. As such we'd require a reproduction to investigate this further.

  4. Michael-7 commented on Jun 23, 2023

    @Michael-7

    @alan-agius4 thanks! I'll try to make a reproduction in another repo.

  5. Michael-7 commented on Jun 23, 2023

    @Michael-7

    @alan-agius4 I created a repro: https://github.com/Michael-7/angular-repro

    The problem happens as soon as you add two "projects" in the angular.json file.

    In the repro if you try the ng g component language command in the angular-repro-45/src/app folder for example, it gives the error

  6. alan-agius4 commented on Jun 23, 2023

    @alan-agius4
    Collaborator

    What is happening here is that the Angular CLI cannot determine which project you intent to run the schematic in (Due to the removal of defaultProject. We should definitely improve the error message here and explain what actions the users need to take.

    You can either provide the project using the --project option or change the current working directory to a project directory.

  7. Michael-7 commented on Jun 23, 2023

    @Michael-7

    Yes, it also cannot determine it because both projects have the same root. I need to generate 2 projects from the same root so it would never know what project to pick. So I will set a "defaultProject". It works when I add the --project <project-name>. Thanks for helping out!

  8. sergey-morenets commented on Jun 23, 2023

    @sergey-morenets
    Author

    Hi @alan-agius4

    Yes, you're right. I found this project in my angular.json:

    "project-e2e": {
          "root": "",
          "sourceRoot": "",
          "projectType": "application",
          "architect": {
            "e2e": {
              "builder": "@angular-devkit/build-angular:protractor",
              "options": {
                "protractorConfig": "./protractor.conf.js",
                "devServerTarget": "project:serve"
              }
            }
          }
        }
    

    I didn't add it manually. I guess it was added automatically while creating new application (at least until Angular 11).
    Once I removed it from angular.json this issue doesn't reproduce any more.
    So I guess the error message should be more descriptive and states about multiple projects in angular.json.

  9. sherlock1982 commented on Aug 28, 2023

    @sherlock1982

    Do I get it correct that now it's not recommended to have two projects inside angular.json?
    Cause I have no idea how I can fix it for example when running from Webstorm

  10. vmachacek commented on Oct 20, 2023

    @vmachacek

    I have 3 projects in my angular.json and IDE has option for "Extract Component" refactoring which is great help, however it fails because the CLI fails, I could really utilize something like defaultProject..

  11. nsmithdev commented on Nov 29, 2023

    @nsmithdev

    ng build has a nice error message but the default project would be even better for me.

    image

  12. radavel commented on Feb 13, 2024

    @radavel

    I had this issue trying to generate a new component, In my case I reviewed my angular.json file and I saw that I had 2 projects, so I just ran the following command using the first one project:

    ng generate component {componentName} --project={projectName}

  13. wbuck commented on Apr 18, 2024

    @wbuck

    We also have two projects defined with the same root directory.
    We recently updated to Angular 15 (which removed the defaultProject key) and started seeing the following error when attempting to generate some schematic via ng generate component User:

    Data path "" must have required property 'project'.

    Since the projects have the same root, changing directories does not work.
    Specifying the --project option to ng generage does work however.

    I've also noticed that I can define schematics at the top level of the angular.json file.
    For each schematic I can specify a project option, for example:

    {
        "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
        "version": 1,
        "newProjectRoot": "projects",
        "projects": { 
             "project1": {...},
             "project2": {...}
         },
        "schematics": { 
            "@schematics/angular:component": {
                "prefix": "app",
                "style": "scss",
                "project": "project1" <-- Added the project key
            },
        }
    }
    

    Adding the project key to the schematic also seems to work, i.e., ng generate component User now works as expected.
    In our case this makes sense since both projects share the same root directory.
    The downside with this is I have to specify a schematic for each schematic: component, directive, pipe, module, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions