Skip to content

ng generate using wrong root directory on upgraded Angular application (5 -> 6) #11433

@sjdecaro

Description

@sjdecaro

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Area

- [ ] devkit
- [ ] schematics

(Unsure at this time which area it affects.)

Versions

Node: 8.11.3
npm: 6.1.0
Angular CLI (global): 6.0.8

Repro steps

When ng update @angular/cli is run on an Angular 5 project, the angular.json file that gets generated has an improper setting in the e2e section of the configuration that interferes with the behavior of ng generate.

    "test-ng5-app-e2e": {
      "root": "",
      "sourceRoot": "e2e",
      ...
    }

Steps:

  • Create a new Angular 5 project (I used these steps: https://stackoverflow.com/a/50467119/6189080)
  • Install the latest CLI version on the project (npm install @angular/cli@6.0.8)
  • Run ng update @angular/cli on the project
  • From the source folder of the project, run:
    • ng generate service test --dry-run
    • ng generate component test --dry-run

The log given by the failure

$ ng g s test --dry-run
CREATE e2e/app/test.service.spec.ts (362 bytes)
CREATE e2e/app/test.service.ts (133 bytes)

NOTE: Run with "dry run" no changes were made.

$ ng g c test --dry-run
Could not find an NgModule. Use the skip-import option to skip importing in NgModule.

Desired functionality

ng generate works correctly out of the box on an upgraded application.

The simplest version would be to have the default settings match the initial settings for a newly-generated Angular 6 project.

    "test-ng6-app-e2e": {
      "root": "e2e/",
      ...
    }

Mention any other details that might be useful

I first ran across the fix in this StackOverflow comment. I have reproduced this fix in my own project, and ng generate is now working as expected.

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