Skip to content

ng generate component mymodule/mycomp fails when project root set deep #8653

@Red-3

Description

@Red-3

Versions

Angular CLI: 1.5.2
Node: 8.2.1
OS: linux x64
Angular: 4.4.6
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router, tsc-wrapped
@angular/cdk: 2.0.0-beta.12
@angular/cli: 1.5.2
@angular/flex-layout: 2.0.0-beta.9
@angular/material: 2.0.0-beta.12
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.21
@angular-devkit/schematics: 0.0.37
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.2
@schematics/angular: 0.1.7
typescript: 2.3.4
webpack: 3.8.1

Repro steps

The root of the @angular project in .angular-cli.json is src/main/webapp

  • Step 1 - Navigate to root folder of project
  • Step 2 - ng generate component mymodule/mycomp
  • Step 3 - ng generate component mymodule/mycomp --skip-import

Observed behavior

Step 2

Error: Could not find an NgModule for the new component. Use the skip-import option to skip importing components in NgModule.
Could not find an NgModule for the new component. Use the skip-import option to skip importing components in NgModule.

Step 3
Component is created in wrong directory. Full path of component is created in root/app, not at root/app (i.e. path is doubled - see below)

src/main/webapp/src/main/webapp/app/mymodule/mycomp.component.scss

Desired behavior

Component created in the correct location and imported into the project module.

Mention any other details that might be useful (optional)

  • I created a new component a couple of weeks ago, but since then I have upgraded several components, including @angular/core, @angular/material and @angular/flex-layout
  • (Project was originally created with JHipster - Java/SpringBoot backend.)
  • To troubleshoot, I created a new project with ng new myproj --source-dir src/main/webapp and it created the component OK. But this project is too complex to create afresh and port code over.
  • BTW - --source-dir option is not documented

FAO: @hansl

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions