You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Data path "" must have required property 'project'. #25402
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'.
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.
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.
@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.
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.
Reacted by Trang Le, Arashi, Len Chang, Alfredo Delgado, Patrick, Piyawan Yosathorn, Kenny Lai, aminisana, Radamés Edrey Hernández, Murhaf Sousli and 8 more
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!
Reacted by Najeeeeeem, aminisana and Warren Buckley
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.
Reacted by Ivan Sager, Jamie McIntyre, Moritz A. Vieli, dufei-7, jrbistuer and Sanjid Haque
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
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..
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}
Reacted by trungnghiancc, Jahanzaib , Ashley Arik, Vladimir Varbanov, peterhexakia and Md Masum Mollik
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:
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.
Reacted by David Boothe, Igor Kosteski, John Farrell, Nikolai Orekhov, cebbec and Daniel Kucal
Activity
alan-agius4 commentedon Jun 22, 2023
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-appand 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.
Michael-7 commentedon Jun 23, 2023
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:
Can't do the
ng g component languagescommand for example. Doesn't work in component or in the app folder.My env:
I think it might have something to do with me adding extra projects - and renaming the current project - in the
angular.jsonfile and it now expecting I have aprojectsfolder because before I did that it worked fine.alan-agius4 commentedon Jun 23, 2023
@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.
Michael-7 commentedon Jun 23, 2023
@alan-agius4 thanks! I'll try to make a reproduction in another repo.
Michael-7 commentedon Jun 23, 2023
@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.jsonfile.In the repro if you try the
ng g component languagecommand in theangular-repro-45/src/appfolder for example, it gives the erroralan-agius4 commentedon Jun 23, 2023
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
--projectoption or change the current working directory to a project directory.Michael-7 commentedon Jun 23, 2023
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!sergey-morenets commentedon Jun 23, 2023
Hi @alan-agius4
Yes, you're right. I found this project in my angular.json:
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.
sherlock1982 commentedon Aug 28, 2023
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
vmachacek commentedon Oct 20, 2023
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..
nsmithdev commentedon Nov 29, 2023
ng build has a nice error message but the default project would be even better for me.
radavel commentedon Feb 13, 2024
I had this issue trying to generate a new component, In my case I reviewed my
angular.jsonfile 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}wbuck commentedon Apr 18, 2024
We also have two projects defined with the same root directory.
We recently updated to
Angular 15(which removed thedefaultProjectkey) and started seeing the following error when attempting togeneratesome schematic viang generate component User:Since the projects have the same root, changing directories does not work.
Specifying the
--projectoption tong generagedoes work however.I've also noticed that I can define
schematicsat the top level of theangular.jsonfile.For each
schematicI can specify aprojectoption, for example:Adding the
projectkey to the schematic also seems to work, i.e.,ng generate component Usernow 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
schematicfor eachschematic:component,directive,pipe,module, etc.