angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Unhelpful warning running ng g c with multiple projects sharing the same root

Open CodySchrank opened this issue 8 years ago • 35 comments

Bug Report or Feature Request (mark with an x)

- [X ] bug report
- [ ] feature request

Area

- [X ] devkit
- [ ] schematics

Versions

node: v8.11.3 npm: 6.1.0 ng cli: 6.1.0-rc.1

Repro steps

Create an angular.json with multiple projects. Set 1 as default project. Run ng g c

The log given by the failure

"Two or more projects are using identical roots. Unable to determine project using current working directory. Using default workspace project instead."

Desired functionality

This warning is extraneous when a default project is set and doesn't offer a solution to silence it. Instead of a warning it should just use the default project if one is set.

CodySchrank avatar Jul 12 '18 21:07 CodySchrank

I had the same error message when running the command ng add @angular/pwa --project ng-zero

I then followed @ThuwarakeshM 's advice and had the "root": "e2e" in the angular.json file and it solved the issue.

stephaneeybert avatar Oct 12 '18 16:10 stephaneeybert

I started getting this error after i added angular-playground. so i removed the entire "playground" section from angular.json.

the error is gone and the project seems to be working fine.

ghost avatar Oct 29 '18 07:10 ghost

Just in case someone need it, I had the same problem here,

npm clean cache --force
rm -rf node_modules/
rm package-lock.json
npm install

those commands did the job!

rbenal avatar Oct 29 '18 19:10 rbenal

Just in case someone need it, I had the same problem here,

npm clean cache --force
rm -rf node_modules/
rm package-lock.json
npm install

those commands did the job!

npm clean cache --force should be npm cache clean --force. You flipped the two 'c' commands.

WKenya avatar Oct 31 '18 19:10 WKenya

I just got the same error; nodem_modules HAD been removed while upgrading the project.

It is a 'default' project with IBM's LoopBack, configured as a 'server' project, and a 'client' project that has Angular in it.

There is but one angular.json; it's inside .\client\angular.json

It DID put the component I was creating in the right place, namely src\app\app-routing.module.ts and updated the correct .\client\src\app\app.module.ts

I had tried this project before with Angular 'at the root' and a subdirectory called 'serverapi' with the LoopBack project in it, but that didn't seem to work as well, so I upgrade and restructured to the 'sample' configuration (per IBM).

Now I got this error, which seems weird as the angular.json is in the same directory I'm running the CLI in.

I had a BIG MESS of incompatible versions in this project, and tried to straightened everything out by upgrading everything. Here's the CLI -v:

Angular CLI: 7.2.2
Node: 10.7.0
OS: win32 x64
Angular: 7.2.2
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, http, language-service, material, platform-browser
... platform-browser-dynamic, platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.3
@angular-devkit/build-angular     0.12.3
@angular-devkit/build-optimizer   0.12.3
@angular-devkit/build-webpack     0.12.3
@angular-devkit/core              7.2.3
@angular-devkit/schematics        7.2.2
@ngtools/webpack                  7.2.3
@schematics/angular               7.2.2
@schematics/update                0.12.2
rxjs                              6.3.3
typescript                        3.2.4
webpack                           4.28.4

jgwinner avatar Jan 27 '19 00:01 jgwinner

I have solved my problem by specifying the root property of my second project to e2e. That is I changed this:

"myproject-e2e": {
      "root": ""

to:

"myproject-e2e": {
      "root": "e2e",

This will bring up a new error when we try to create new components

More than one module matches. Use skip-import option to skip importing the component into the closest module. This can then be solved by specifying the module name in the cli

ng generate component comp_name --module=app.module

As suggested by @ThuwarakeshM, you can set a specific root for each project, however there is another fix which is to set the "defaultProject" at the root level of angular.json to the name of the main project. This means you aren't then required to change the root but it's probably best to configure both of these settings.

mbrookson avatar Mar 06 '19 22:03 mbrookson

@mbrookson Adding a root value in the angular.json for my e2e project fixed it.

marc-wilson avatar Mar 15 '19 16:03 marc-wilson

I got that error when tried to create a new component outside the app folder... I moved to the right folder and execute again... silly of me... (App\src\app)

eraigosa avatar Mar 15 '19 17:03 eraigosa

Check the given link..

https://github.com/catalogicsoftware/ngx-dynamic-dashboard-framework/issues/21

Resolved.

ashutosh15aashu avatar Apr 24 '19 07:04 ashutosh15aashu

@AlistairBates solution worked for me. Warning gone....

mhadji avatar Jul 11 '19 14:07 mhadji

use <ng g c mycomponent --skip-import> it works fine

jordybayo avatar Jan 22 '20 04:01 jordybayo

I was having this issue, after checking angular.json file, i found out there was no route defined

"root": ""

I changed it to

"root": "app"

where app was the name of the folder where i was having everything for the project, and it worked for me.

haisumkundi avatar Apr 07 '20 09:04 haisumkundi

Hey, all I see lot of people are having issue with Two or more projects are using identical roots. Unable to determine project using current working directory. Using default workspace project instead. Two or more projects are using identical roots. Unable to determine project using current working directory. Using default workspace project instead. More than one module matches. Use skip-import option to skip importing the component into the closest module.

Please use this: while generating a component specify the module that u wanted to import in. ng g c nameOfTheComponent --module=nameOfTheModule

ravigudur avatar Apr 14 '21 12:04 ravigudur

Thanks for reporting this issue. Luckily, it has already been fixed in one of the recent releases. Please update to the most recent version to resolve the problem.

If the problem persists in your application after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior. You can use ng new repro-app to create a new project where you reproduce the problem.

alan-agius4 avatar Jun 01 '21 07:06 alan-agius4

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.