8

I'm trying to build my Angular 5 app, and I'm getting the error:

Cannot determine the module for class ThreadListTabsComponent in /home/brightwater/Differ/src/app/thread-lists/thread-lists.component.ts! Add ThreadListTabsComponent to the NgModule to fix it.

This is confusing because I'm importing the offending component in the module:

thread-lists.module.ts:

import { OtherModules } from './modules-everywhere';
import { NgModule }      from '@angular/core'

import { SomeOtherComponents }  from './other-components.component';
import { ThreadListTabsComponent } from './thread-list-tabs.component';

@NgModule({
  imports: 
  [ 
    OtherModules
  ],
  declarations: [
    OtherComponents,
    ThreadListTabsComponent
  ],
  exports: [
    OtherComponents,
    ThreadListTabsComponent
  ],
  providers: [ ThreadListsService ]
})


export class ThreadListsModule { }

Here's the component:

thread-list-tabs.component.ts

import { Component } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Router }   from '@angular/router';
import { ThreadListsService }   from './thread-lists.service';

@Component({
  moduleId: module.id,
  selector: 'thread-list-tabs',
  templateUrl: 'thread-list-tabs.component.html',
  styleUrls: ['thread-list-tabs.component.css']
})


export class ThreadListTabsComponent {

  // Stuff this component does

}

app.module.ts

import { NgModule } from '@angular/core'
import { ThreadListsModule } from './thread-lists/thread-lists.module'
import { OtherModules } from './other.modules'
import { AppComponent } from './app.component'

@NgModule({
  imports: [    
    OtherModules, 
    ThreadListsModule
  ],
  declarations: [ 
    AppComponent
  ],
  providers: [ SomeService ],
  bootstrap: [ AppComponent ]
})

export class AppModule { }

Is there something I'm missing?

Vikas
  • 11,859
  • 7
  • 45
  • 69
J. Adam Connor
  • 1,694
  • 3
  • 18
  • 35
  • Try adding import { NgModule } from '@angular/core'; in your module? – Juan Apr 28 '18 at 01:33
  • It's there. I just didn't include it here for the sake of concision. Updated my question to reflect this. – J. Adam Connor Apr 28 '18 at 01:35
  • Can you post your app module? – Juan Apr 28 '18 at 01:44
  • I see `TrendingThreadListComponent` in your module setup but not `ThreadListTabsComponent`. Did you forget to add it? – Daniel W Strimpel Apr 28 '18 at 01:50
  • Yeah, that was an accident. It's in there, too. Also, I've updated the question to show `app.module.ts`. – J. Adam Connor Apr 28 '18 at 01:51
  • What happens if you remove the `moduleId` in your component setup? Pretty sure webpack sets that up for you if needed. You might need to make your template and CSS URLs relative tho using the `./` at the beginning – Daniel W Strimpel Apr 28 '18 at 01:54
  • https://angular.io/guide/change-log#all-mention-of-moduleid-removed-component-relative-paths-guide-deleted-2017-03-13 – Daniel W Strimpel Apr 28 '18 at 01:59
  • @DanielWStrimpel that was one of the first things I tried. Plus, I use it in every other component with no complaints. – J. Adam Connor Apr 28 '18 at 02:34
  • 2
    That error is complaining about a class in the `thread-lists.component.ts` file but you have the `thread-list-tabs.component.ts` file shown above. Is it possible that you are looking in the wrong file for the problem class? – Daniel W Strimpel Apr 28 '18 at 02:48
  • 2
    Good eye! thread-lists and thread-list-tabs a duplicate components. This fixed the issue. You're welcome to post the answer if you like and I'll accept--though I wonder how helpful such answers are, as they're so specific and related to my own blindness... Thank you, though. – J. Adam Connor Apr 28 '18 at 03:03

1 Answers1

13

This looks like a filename casing problem, see the issue described on angular git repo (https://github.com/angular/angular-cli/issues/10732)

Nate Anderson
  • 18,334
  • 18
  • 100
  • 135
Thom Kiesewetter
  • 6,703
  • 3
  • 28
  • 41
  • 2
    That was my problem. The file name/path case in the import string was not the same as on the file system. – Zarepheth Jul 24 '18 at 16:03
  • Similar to the answer (and git issue) mentioned [here](https://stackoverflow.com/a/51274722/1175496) , also [here (where they suggest some other possible fixes)](https://stackoverflow.com/a/50475168/1175496) – Nate Anderson Sep 22 '19 at 21:18