简体   繁体   中英

Import Error on Stackblitz when trying to add component to module file

I'm using Stackblitz to practice angularJS and it's coming up with an error when I attempt to import a component in the app.module.ts file.

Import error, can't find file:
./heroes/heroes.component

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';
import { HeroesComponent } from './heroes/heroes.component';

https://stackblitz.com/edit/angular-akxx4e?file=src%2Fapp%2Fapp.module.ts

Update below Changes, because it's in different folder

import { HeroesComponent } from '../heroes/heroes.component';

Method 1

This issue occurs due to component creation inside wrong location. So heroes component should be created inside app root. This is the recommended answer.


Method 2

Correcting component's relative path is also works. But it is not the correct answer.

import { HeroesComponent } from '../heroes/heroes.component';

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