Skip to content
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

Angular cli Generates Wrong Directory Path in app.module.ts #7135

Closed
1 of 2 tasks
djtahl opened this issue Jul 25, 2017 · 23 comments · Fixed by #7284
Closed
1 of 2 tasks

Angular cli Generates Wrong Directory Path in app.module.ts #7135

djtahl opened this issue Jul 25, 2017 · 23 comments · Fixed by #7284
Labels
needs: investigation Requires some digging to determine if action is needed P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity5: regression type: bug/fix

Comments

@djtahl
Copy link

djtahl commented Jul 25, 2017

Bug Report or Feature Request (mark with an x)

  • bug report
  • feature request

Versions.

node -v : v6.10.0
npm -v : 5.3.0
ng -v :

@angular/cli: 1.2.4
node: 6.10.0
os: darwin x64

Repro steps.

  • install the latest angular-cli (version : 1.2.4)
  • go in the desired repository
  • run the command ng new myProject
  • go in the created project
  • go in myProject/src/app and create a folder "common"
  • go in "common" folder
  • run ng g c myComponent

The log given by the failure.

  • the component is created at the right location :
installing component
  create src/app/common/my-component/my-component.component.css
  create src/app/common/my-component/my-component.component.html
  create src/app/common/my-component/my-component.component.spec.ts
  create src/app/common/my-component/my-component.component.ts
  update src/app/app.module.ts
  • but the path written in "app.module.ts" is wrong
ERROR in /Users/u.name/myProject/src/app/app.module.ts (5,38): Cannot find module './common/src/app/common/my-component/my-component.component'.

ERROR in ./src/app/app.module.ts
Module not found: Error: Can't resolve './common/src/app/common/my-component/my-component.component' in '/Users/u.name/myPoject/src/app'
 @ ./src/app/app.module.ts 10:0-99
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

Desired functionality.

The path written is constantly adding "src/app" part whereas older version of the cli did not have this behavior
The correct import statement should be :
import { MyComponentComponent } from './common/my-component/my-component.component';

Mention any other details that might be useful.

This issue has also been reported on StackOverflow by another user :
https://stackoverflow.com/questions/45293787/angular-cli-generates-wrong-directory-path-in-app-module-ts

@exequiel09
Copy link

Not only in app.module.ts. i have nested modules that contains components which i generate using the command ng g c <component_name>. What happens is that it prepends the import path with ./src/app. It should be ./ or ./<current_working_directory>.

Versions.

@angular/cli: 1.2.4
node: 6.11.0
os: darwin x64
@angular/animations: 4.3.1
@angular/common: 4.3.1
@angular/compiler: 4.3.1
@angular/core: 4.3.1
@angular/forms: 4.3.1
@angular/http: 4.3.1
@angular/platform-browser: 4.3.1
@angular/platform-browser-dynamic: 4.3.1
@angular/router: 4.3.1
@angular/cli: 1.2.4
@angular/compiler-cli: 4.3.1
@angular/language-service: 4.3.1

@fsx999
Copy link

fsx999 commented Jul 26, 2017

i have the same issue

@Itisfilipe
Copy link

+1

@hiepxanh
Copy link
Contributor

me too

@cyrilletuzi
Copy link
Contributor

cyrilletuzi commented Jul 28, 2017

I confirm this issue, I was about to open a ticket.

More details about the problem :

ng new test
cd test
ng g component first

is OK, but :

cd src/app (or any other dir)
ng g component second

generates an invalid path (and thus a compile error) in AppModule :
import { SecondComponent } from './src/app/second/second.component';

@filipesilva I suspect it's due to the new change of baseUrl in tsconfig.json in #6861 , even if reverting back to old config doesn't solve the problem.

A test is missing, a regression on such a basic command is not normal.

@filipesilva filipesilva added needs: investigation Requires some digging to determine if action is needed P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity5: regression type: bug/fix labels Jul 28, 2017
@filipesilva
Copy link
Contributor

@Brocco can you have a look?

@djtahl
Copy link
Author

djtahl commented Jul 30, 2017

I've checked on an older angular-cli version and found one that didn't had the issue :
angular-cli 1.0.6 didn't had this generated path issue

@deveshjadon98
Copy link

@djtahl same case with me, it was working fine with 1.0.6 but after updating to 1.2.4 it's giving wrong relative path.

@deveshjadon98
Copy link

deveshjadon98 commented Jul 31, 2017

I am facing one more issue related to this. After updating to 1.2.4, the import statement of environment object is changed to import { environment } from 'environments/environment'; and i had make it relative again manually at every place.

@cyrilletuzi
Copy link
Contributor

Any news about this ?

There is currently 3 major problems with generation (this one, #6533 and #7061). Some of them dating from several weeks ago, and I'm quite worried to see new versions of the CLI released without any fix for these major regressions. I tried to help with a PR for one of them, posted one month ago, but which has been completely ignored.

Speed is nice, but a working tool should be a priority. Currently the generation has become so buggy I'm starting to think about stopping to use it during the trainings I do...

@andonyns
Copy link

andonyns commented Aug 7, 2017

+1

@keatkeat87
Copy link

1.3.0 still same..

@miguelcaravantes
Copy link

same problem

@SeanConnell93
Copy link

@djtahl OMG thank you, I just changed it to the right path. Not a nice thing to get when your just new to it.

andrewkww added a commit to andrewkww/angular-cli that referenced this issue Aug 17, 2017
andrewkww added a commit to andrewkww/angular-cli that referenced this issue Aug 17, 2017
@andrewkww
Copy link
Contributor

This issue has been fixed in the master branch. However, the issue still exist in 1.3.x and 1.4.x branch.

andrewkww added a commit to andrewkww/angular-cli that referenced this issue Aug 18, 2017
andrewkww added a commit to andrewkww/angular-cli that referenced this issue Aug 18, 2017
@filipesilva
Copy link
Contributor

Fixed via #7090

@ingcrengifo
Copy link

same problem :(

@hansl
Copy link
Contributor

hansl commented Aug 23, 2017

This issue was fixed in 1.4.0, but not 1.3. We are looking at fixing it in 1.3 as well.

@andrewkww
Copy link
Contributor

Great! Thanks @hansl !

@nemeth-tibor
Copy link

I use 1.6.3 and ng new project-name still results:

Error: Path "/app/app.module.ts" does not exist.
Path "/app/app.module.ts" does not exist.

dond2clouds pushed a commit to d2clouds/speedray-cli that referenced this issue Apr 23, 2018
@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 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: investigation Requires some digging to determine if action is needed P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity5: regression type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.