Skip to content
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

ng generate adds component to module even if the generated component is identical #4323

Closed
beeman opened this issue Feb 1, 2017 · 7 comments · Fixed by #4446
Closed

ng generate adds component to module even if the generated component is identical #4323

beeman opened this issue Feb 1, 2017 · 7 comments · Fixed by #4446

Comments

@beeman
Copy link
Contributor

beeman commented Feb 1, 2017

Please provide us with the following information:

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

macOS Sierra

Versions.

Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here:

angular-cli: 1.0.0-beta.28.3
node: 7.2.0
os: darwin x64
@angular/common: 2.4.5
@angular/compiler: 2.4.5
@angular/core: 2.4.5
@angular/forms: 2.4.5
@angular/http: 2.4.5
@angular/platform-browser: 2.4.5
@angular/platform-browser-dynamic: 2.4.5
@angular/router: 3.4.5
@angular/compiler-cli: 2.4.5

Repro steps.

Was this an app that wasn't created using the CLI? What change did you do on your code? etc.

Create an app with ng new

Follow these steps:

$ ng g m events
installing module
  create src/app/events/events.module.ts

$ ng g c events/list
installing component
  create src/app/events/list/list.component.css
  create src/app/events/list/list.component.html
  create src/app/events/list/list.component.spec.ts
  create src/app/events/list/list.component.ts
  update src/app/events/events.module.ts

$ ng g c events/list
installing component
  identical src/app/events/list/list.component.css
  identical src/app/events/list/list.component.html
  identical src/app/events/list/list.component.spec.ts
  identical src/app/events/list/list.component.ts
  update src/app/events/events.module.ts

$ cat src/app/events/events.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ListComponent } from './list/list.component';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [ListComponent, ListComponent]
})
export class EventsModule { }

Because the last generate command generates all identical files I don't expect the update of the module to happen, as this will leave it with the same component being declared twice.

The log given by the failure.

Normally this include a stack trace and some more information.

No failures.

Mention any other details that might be useful.


Thanks! We'll be in touch soon.

@Meligy
Copy link
Contributor

Meligy commented Feb 1, 2017

Quick hint: A temporary workaround for now is:

If you know you are adding the same component again (I imagine for example you want to add a .spec or style file that you didn't generate the first time), you can use the argument --skip-import to skip adding it to module.

@Meligy
Copy link
Contributor

Meligy commented Feb 1, 2017

Can you please confirm whether this is still the case with latest version?

@beeman
Copy link
Contributor Author

beeman commented Feb 1, 2017

Great tip @Meligy .

It's the latest version angular-cli: 1.0.0-beta.28.3. Actually I just came across when testing the new release, @hansl told me to create the issue.

@Meligy
Copy link
Contributor

Meligy commented Feb 1, 2017

Oops. Sorry I read that as 20 not 28. Bad bad eyes.

delasteve added a commit to delasteve/angular-cli that referenced this issue Feb 6, 2017
delasteve added a commit to delasteve/angular-cli that referenced this issue Feb 6, 2017
"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

fixes angular#4323
delasteve added a commit to delasteve/angular-cli that referenced this issue Feb 6, 2017
"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

fixes angular#4323
delasteve added a commit to delasteve/angular-cli that referenced this issue Feb 6, 2017
"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

Closes angular#4323
delasteve added a commit to delasteve/angular-cli that referenced this issue Feb 6, 2017
"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

Closes angular#4323
delasteve added a commit to delasteve/angular-cli that referenced this issue Feb 6, 2017
"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

Closes angular#4323
delasteve added a commit to delasteve/angular-cli that referenced this issue Feb 7, 2017
"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

Closes angular#4323
delasteve added a commit to delasteve/angular-cli that referenced this issue Feb 7, 2017
"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

Closes angular#4323
delasteve added a commit to delasteve/angular-cli that referenced this issue Feb 7, 2017
"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

Closes angular#4323
delasteve added a commit to delasteve/angular-cli that referenced this issue Feb 7, 2017
"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

Closes angular#4323
delasteve added a commit to delasteve/angular-cli that referenced this issue Feb 9, 2017
"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

Closes angular#4323
delasteve added a commit to delasteve/angular-cli that referenced this issue Feb 9, 2017
"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

Closes angular#4323
hansl pushed a commit that referenced this issue Feb 17, 2017
…ymbol (#4446)

"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

Closes #4323
asnowwolf pushed a commit to asnowwolf/angular-cli that referenced this issue Apr 12, 2017
…ymbol (angular#4446)

"ng g c X" will no longer insert the component symbol in the NgModule's declaration array should it already exist.

Closes angular#4323
@khemrajiitk
Copy link

use this
ng generate component menu --skip-import=true

@merwynpawar
Copy link

in vs code you have terminal u can select the folder an right click on that folder an select the option from the drop down open in terminal

@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 Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants