Vince
Vince

Reputation: 27

Need to fix error not found in module - Angular

I'm practicing angular, but received this error while compiling my code:

Module not found: Error: Can't resolve './app.component.css' in 'D:\hello-world-app\src\app'
i 「wdm」: Failed to compile.

My app.component.html

<h1>Angular</h1>
<courses></courses>

My courses.component.ts

// tslint:disable-next-line: import-spacing
import{Component} from '@angular/core';


@Component({
  selector: 'courses', //<courses>
  template: '<h2>Courses</h2>'
})
export class CoursesComponent {

}

My app.component.ts


import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'hello-world-app';
}

My app.module.ts

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

import { AppComponent } from './app.component';
import { CoursesComponent } from './courses.component';

@NgModule({
  declarations: [
    AppComponent,
    CoursesComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Upvotes: 2

Views: 1001

Answers (1)

Jacques
Jacques

Reputation: 3774

Angular is failing to find (resolve) the file, just as the error states. In order to fix the error, you need to either add the file, or delete the line styleUrls: ['./app.component.css']

If you do not want to avoid the file reference and are using angular cli (if you're not, you probably should be), you can use --inlineStyle=true when generating a component. Granted, if you're using angular cli, the css file should have been created when the component was generated.

Odds are either you copy pasted some stuff, or mistakenly deleted that file. Either way, Angular will always complain when it can't find something you're referencing. (Much like pretty much every other programming framework/system/language)

Upvotes: 1

Related Questions