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 Generator does not always save components in correct directory

See original GitHub issue

like #6431

Bug Report or Feature Request (mark with an x)

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

Versions.

@angular/cli: 1.2.7 node: 6.10.1 os: darwin x64 @angular/animations: 4.3.3 @angular/cdk: 2.0.0-beta.8 @angular/common: 4.3.3 @angular/compiler: 4.3.3 @angular/core: 4.3.3 @angular/flex-layout: 2.0.0-beta.8 @angular/forms: 4.3.3 @angular/http: 4.3.3 @angular/material: 2.0.0-beta.8 @angular/platform-browser: 4.3.3 @angular/platform-browser-dynamic: 4.3.3 @angular/router: 4.3.3 @angular/cli: 1.2.7 @angular/compiler-cli: 4.3.3

Mac OS Sierra

Repro steps.

It’s hard to give repo steps because I haven’t discovered exactly what I have to do to reproduce. However, once the behaviour starts for a project, it continues to behave this way. The only way I have found to fix it is to start a completely new project and copy all my code over.

The issue is well described in #6431. In brief,

  1. I cd to a module directory in my project eg: app/admin

  2. I create a new component, eg ng g c users

Instead of creating the new component inside app/admin/users, it creates it inside app, eg app/users

In addition it creates an incorrect import statement in app.module, eg: import { UsersComponent } from './admin/src/app/users/users.component';

I have seen this happen twice now. I can be working with a project for months and months with it working correctly, then one day it just stops working the way it should. The only way I have been able to fix it is to generate a completely new project and copy all my code over to the new project.

The log given by the failure.

N/A

Desired functionality.

It should create the component inside the admin directory, eg: app/admin/users

and it should create a well formed import statement in admin.module, eg: import { UsersComponent } from './users/users.component';

Mention any other details that might be useful.

When I create a brand new project it does what I want it to. I have no idea what I do to provoke this behaviour. I have gone through the following files with a fine tooth comb and can’t find anything wrong:

  • .angular-cli.json
  • package.json
  • tsconfig.json
  • src/tsconfig.app.json

I can’t think of anywhere else to look.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:21 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
chriscurnowcommented, Oct 4, 2017

Any update on this issue?

2reactions
grizzm0commented, Aug 14, 2017

@exequiel09 I was simply explaining why the error happens and how he can solve it for now. 😃 This is how ng is supposed to be used. From the looks of the other issues it seems like it’ll be “fixed” tho.

I don’t see what a complex folder structure has to do with anything other than auto-completing with tab in the terminal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to generate components in a specific folder with Angular ...
Method 1: "Open in Integrated Terminal" - Quick, Simple and Error free method · Right click on the folder in which you want...
Read more >
ng generate component using the CLI - Pluralsight
ng generate component is a simple one-line command which creates different files and a folder, and it references the newly created component ......
Read more >
Dynamic component loader - Angular
This cookbook shows you how to add components dynamically. See the live example / download example of the code in this cookbook.
Read more >
Automatically generate React components with Plop.js
In this post, we'll demonstrate Plop's capabilities by building a React component generator. What is Plop.js? The Plop.js library can be used ...
Read more >
Guide for All-Hazard Emergency Operations Planning - FEMA
Chapters 4 and 5 list and discuss elements that, if applicable for a jurisdiction, ... Those who draft an EOP must understand what...
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