Skip to content

Generating component with Angular CLI writes code two characters too early #7732

Closed

Description

@artemdru

In Angular 4, whenever I use the CLI to create a component (for example, using this command: "ng g c successAlert"), the app.module.ts file does not generate the correct code - it's as if though the code is written two characters too early. For example, if warningAlert were my last added component:

import { WarningAlertComponent } from './warningAlert/warningAlert.component';

@NgModule({
  declarations: [
    WarningAlertComponent
  ]
})

And if I were to execute in the CLI "ng g c successAlert", the app.module.ts file would be updated like so:

import { WarningAlertComponent } from './warningAlert/warningAlert.componen;
import { SuccesAlertComponent } from './success-alert/succes-alert.component't';

@NgModule({
  declarations: [
    WarningAlertCompone,
    SuccessAlertComponentnt
  ]
})

As you can see, there is an error both in the import line, and in the declarations line. This error with two characters is consistent.

If it's relevant, I'm using Sublime Text 3 and the command is being written into the Glue console.

Activity

  1. textbook commented on Sep 18, 2017

    @textbook

    This doesn't happen for me with v1.4.2, even if I also mangle an existing component to use the unconventional formatting shown in your example (i.e. './warningAlert/warningAlert.component' rather than './warning-alert/warning-alert.component').

  2. self-assigned this
    on Sep 22, 2017
  3. Duh-Rell commented on Sep 24, 2017

    @Duh-Rell

    Having the same problem. Downgraded from 1.4.3 to 1.4.0 incrementally and the problem still persists.

    Edit: When I created the angular project with ng new my global angular-cli version was 1.2.x. I installed angular-cli version 1.4.3 globally and re-ran ng new. Now when I run ng generate component it creates the proper import statements in app.module.ts

  4. kuncevic commented on Sep 30, 2017

    @kuncevic

    I have never had such an issue constantly keeping my cli always upgraded with the latest.
    @artemdru Did you migrated to 1.4.3 or just created a new app?
    If you just create a new app do you have the same problem? Did you try cli 1.4.4?
    @Duh-Rell @artemdru What is your nodejs and OS versions?

  5. fitness23 commented on Sep 30, 2017

    @fitness23

    I'm having the same issue as @artemdru
    I'm on Node 8 with Windows 10. My project was originally on Angular 1.2.x and when I upgraded to 1.4.4 I got the same issue. I can resolve it if I create a new project from scratch but it's going to get far too complicated merging everything over. Has a solution been found to this?

  6. janmegert commented on Apr 10, 2018

    @janmegert

    Same issue. Two characters of previous import/declaration cut off.
    Angular CLI: 1.7.3 Node: 8.11.1 OS: win32 x64 Angular: 5.2.9

  7. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    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.

  8. locked and limited conversation to collaborators on Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions