0

I am trying to import a module into a home-page module, but it is throwing a TypeScript error stating that it cannot find the module despite the fact that it is defined. This is the terminal error -

ERROR in src/app/home-page/home-page.module.ts(11,5): error TS2304: Cannot find name 'UtilityComponentModule'.

My UtilityComponentModule is set up-

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ModalWindowComponent } from './modal-window/modal-window.component';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [
    ModalWindowComponent
  ],
  exports: [
    ModalWindowComponent
  ]
})
export class UtilityComponentModule { }

And the module I'm attempting to import it into is set up as -

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HomePageControllerComponent } from './home-page-controller/home-page-controller.component';
import { LanguageBarComponent } from './language-bar/language-bar.component';
import { SnippetAdderComponent } from './snippet-adder/snippet-adder.component';
import { SnippetCardComponent } from './snippet-card/snippet-card.component';

@NgModule({
  imports: [
    CommonModule,
    UtilityComponentModule
  ],
  declarations: [
    HomePageControllerComponent,
    LanguageBarComponent,
    SnippetAdderComponent,
    SnippetCardComponent
  ],
  exports: [
    HomePageControllerComponent
  ]
})
export class HomePageModule { }

Completely blindsided as to what could be causing this error.

Thank you in advance for any suggestions or direction you have.

Cheers!

2
  • 1
    Where exactly did you import it in your HomePageModule ? You might want to add something like import { UtilityComponentModule } from 'path-to-the-module' Commented Oct 5, 2018 at 18:25
  • This was exactly what I needed to do, but I was trying with just the ./path and had to actually go as far as src/app/path. Thank you for taking the time to answer this question! Commented Oct 5, 2018 at 18:54

1 Answer 1

1

You need to add it to the import list, in the top of your second file as

import { UtilityComponentModule } from 'your path';
Sign up to request clarification or add additional context in comments.

3 Comments

After adding the module to the second file I received another error- ERROR in ./src/app/home-page/home-page.module.ts Module not found: Error: Can't resolve './utility-component/utility-component.module' in '/Users/jbyron/Desktop/code-snip/src/app/home-page' ℹ 「wdm」: Failed to compile. ERROR in src/app/home-page/home-page.module.ts(3,40): error TS2307: Cannot find module './utility-component/utility-component.module'.
I figured it out. This just seems so obvious and I had tried your recommendation and was getting the error I posted above. I wasn't able to use the ./path and I had to actually type out the src/app/path. I have it up and working. Thank you for taking the time to answer this question!
Using ./foo means that you are refering foo that is in your current folder. If you need to go back a folder you need ../. Don't know if that is the case :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.