Angular-cli: ng generate adds component to module even if the generated component is identical

Created on 1 Feb 2017  路  7Comments  路  Source: angular/angular-cli

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.

bufix

All 7 comments

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.

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

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.

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

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

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

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._

Was this page helpful?
0 / 5 - 0 ratings