简体   繁体   中英

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

I'm using:

@angular/cli: 1.2.4
node: 8.2.1
os: linux 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've been using the Angular cli for a while now and today I started a new project on the same machine, same everything. I started the project as usual with ng new mytest . I ran ng serve and everything was fine.

Then I generated a new component in mytest/src/app/ like I always do. This was a navbar component. I ran ng gc navbar . When the Angular cli updated my app.module.ts it wrote:

import { NavbarComponent } from '.src/app/navbar/navbar.component';

This is actually wrong because the component is inside of app/ . When I ran ng serve again it threw an error:

ERROR in /home/ubuntu/angular/mytest/src/app/app.module.ts (5,33): Cannot find module '.src/app/navbar/navbar.component'.

I had to change the import statement to:

import { NavbarComponent } from './navbar/navbar.component'

I don't see how this is possible. I've never had this happen.

Any thoughts?

This is a bug. It is under need: investigation label.

The solution until a fix is going to be implemented is to use @angular/cli: older version.

该错误现已在@ angular / cli 1.3.2中修复。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM