Skip to content

Ng Generator does not always save components in correct directory #7377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chriscurnow opened this issue Aug 14, 2017 · 21 comments
Closed

Ng Generator does not always save components in correct directory #7377

chriscurnow opened this issue Aug 14, 2017 · 21 comments

Comments

@chriscurnow
Copy link

chriscurnow commented Aug 14, 2017

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.

@exequiel09
Copy link

exequiel09 commented Aug 14, 2017

For the wrong import path, Issue #7135 and Pull Requests #7284 and #7090 are related here. Already reported since versions 1.2.x. This is just a duplicate of an existing issue. Fixes and new implementation are already on progress being done by @Brocco

@grizzm0
Copy link
Contributor

grizzm0 commented Aug 14, 2017

The reason it doesn't work as intended is because you're using cd. Use ng in the root of your project and it'll work as intended.

Run the following from the root: ng g c admin/users

@exequiel09
Copy link

exequiel09 commented Aug 14, 2017

@grizzm0 Yes it will work on the root of the project. But what if you have complex directory structure inside the src/app directory? It should be automatically done by the CLI tool itself to correctly resolve the path. This was a regression appeared on what i don't know version.

@grizzm0
Copy link
Contributor

grizzm0 commented 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.

@chriscurnow
Copy link
Author

@grizzm0 this is not how Ng is supposed to work. For the last several months it has worked as I wanted it to in my project. If I start a brand new project, it works how I want it to.
What I don't understand here is why it just starts happening after it has been working perfectly for months on end.
In terms of a complex folder structure, try writing
ng g c contract/subcontract/subcontract-new/supplier-select/new-supplier/new-supplier-with-name/new-supplier-result
I know at least one developer who discarded angular in favour of react on the basis of this issue alone.

@chriscurnow
Copy link
Author

@exequiel09 the issue I am having is actually not the same as #7135.

I am finding it does create the wrong path in app.module but not in the same format as above.

I could actually live with this behaviour although it would be annoying.

The bigger issue is that it creates the component in the wrong directory as described above. This is killing me as it used to work and I'm not sure why it stopped.

@filipesilva filipesilva added P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity5: regression type: bug/fix labels Aug 24, 2017
@krimple
Copy link

krimple commented Aug 28, 2017

We just ran into the src in path thing... Now, I've NEVER used ng generate outside of the root directory, and I've ALWAYS used directory paths. Such as:

ng new foobar
ng g module blah
ng g component blah/blah-blah --module blah

All works, directories are good.

It won't find the module blah when generating the component unless you tell it to create the module in blah/ and refer to the module with its name blah...

Sorry for the blathering on, with the blah blah and all.

Bottom line, if you then start doing cd into directories, it's not a good thing, it'll try relative pathing but then put src/app in there and screw it up.

Is this new? I dunno. But that's the behavior I see.

@ghost
Copy link

ghost commented Aug 31, 2017

i have similar issue. when you use ng g c inside the src directory the generated path in the app.module.ts file is not correct.

@chriscurnow
Copy link
Author

Any update on this issue?

@chriscurnow
Copy link
Author

We'd really like to know how you are going with this issue. When we are working on a complex app it would make it so much easier.

We all know some things can be really difficult to achieve but it was marked as urgent on 24 August.

Any sort of update would be much appreciated.

@zladuric
Copy link

FWIW: for me the path is duplicated. OS: Win 10, node 8.9.2, ng-cli: 1.6.0:

[duricz@msgn07241 ~/temp/my-new-app]$ ng g m new-module
  create src/main/frontend/src/main/frontend/app/new-module/new-module.module.ts (193 bytes)
[duricz@msgn07241 ~/temp/my-new-app]$

FWIW my root path in .angular-cli.json is set to src/main/frontend;

@chriscurnow
Copy link
Author

Hi guys. Can you tell us ANYTHING about progress on this issue.

It was first raised in August. It is no 21st December. It is marked as urgent. But we haven't heard anything???

@chriscurnow
Copy link
Author

chriscurnow commented Feb 5, 2018

@filipesilva - we have now just ticked over to February 2018.

It would be great if you could tell us SOMETHING, ANYTHING.

This is a priority 1, severity 5 issue

@zladuric
Copy link

zladuric commented Feb 5, 2018

My problem was fixed between 1.6.0 and 1.6.4, not sure which one did it.

@chriscurnow
Copy link
Author

chriscurnow commented Feb 6, 2018

That's great @zladuric. Angular CLI is an incredibly good and useful product and I know the team are continually working on it. The problem I have here is the issue was marked a Priority 1 and Severity 5 back in August last year.
Since then we have not heard a peep.
I just find that really strange.
It may well be that the problem is just too hard to solve and I'll just have to get used to creating everything from the root directory – although that would be a real pain. Anyway, if that's the case, it would be nice to hear something about it. The issue is still marked as Open with the highest priority and severity but we hear nothing about it. I just don't get that bit. @filipesilva @Brocco

@hansl hansl assigned Brocco and unassigned Brocco Feb 6, 2018
@hansl hansl added freq3: high and removed P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful labels Feb 6, 2018
@chriscurnow
Copy link
Author

@hansl just interested. What's the priority on this issue now?

@hansl
Copy link
Contributor

hansl commented Feb 7, 2018

@chriscurnow Priority is now based differently, so we don't put it ourselves anymore. Since @Brocco is assigned to your issue we'll get to it soon.

@chriscurnow
Copy link
Author

@hansl Thanks 😄

@chriscurnow
Copy link
Author

@hansl :
It's now May 2018. I reported this in August 2017. Last update here was Feb this year. In Feb you said you would get to it soon.
Look I know the CLI team has been working hard and has made some fantastic additions and fixed up a lot of stuff. I'm not complaining but it would be nice to have some sort of update now and again 😄

@chriscurnow
Copy link
Author

@hansl @filipesilva @Brocco It looks like this has been fixed. I haven't tested all use cases but I just tried it out the other day and everything worked as expected. I can't tell which version because I just haven't tried again until just recently.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants