Modules, Modules, Component Not Found

Using Angular and Nrwl’s NX tool for mono repos, I frequently run into “component not found” or “component not exported” issues. The reason? Well, it has nothing to do with Angular OR Nrwl – it’s a Typescript thing.

Angular Modules reference components, pipes and directives (but not services). This allows Angular to manage dependency injection for the most part.

This is not the same as ES6 or NodeJS modules, which are explicit exports of javascript objects or variables.

Great presentation on the different types of modules

Typescript does not look in the NgModules to resolve type references. For that, you need type files and ES6 modules. Basically, export not only the ngModule that Nrwl sets up for you, but also components, directives, services, etc in index.ts at the root of a lib. I can’t tell you how many times I have forgotten this and spent (too much) time trying to resolve “component not exported”.

I’m hoping this post will help me remember.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.