question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
ved1995commented, Jun 10, 2018

if You are using Angular 6 then change your current directory to /src/app/ then use ng g c new-component. I think the problem will be resolved, It works for me.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 8, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular CLI generate component issue - Stack Overflow
I smell ng finds multiple module files on app root, please supply module while generating component ng generate component componentName ...
Read more >
ng generate - Angular
Generates a new basic application definition in the "projects" subfolder of the workspace. ... Include template inline in the root component.ts file.
Read more >
Generate component with inline template and style using ...
Whenever we want to create a new component using Angular CLI what we usually do is by running below command: > ng generate...
Read more >
The Best Way To Architect Your Angular Libraries
In this section we're going to create new Angular library project ... i -D ng-samurai Angular Schematics collection and use it to generate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found