Angular-cli: Angular cli Generates Wrong Directory Path in app.module.ts

Created on 25 Jul 2017  路  21Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

  • [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

investigation 1 (urgent) regression bufix

Most helpful comment

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.

All 21 comments

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

i have the same issue

+1

me too

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.

@Brocco can you have a look?

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

@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.

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.

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

+1

1.3.0 still same..

same problem

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

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

same problem :(

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

Great! Thanks @hansl !

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.

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._

Was this page helpful?
0 / 5 - 0 ratings