Cannot find module "../components"

I have a components module:

/* root/src/components/components.module.ts */
import { NgModule } from '@angular/core';
// (other imports)
  declarations: [/*components*/],
  exports: [/*components*/]
export class ComponentsModule {}

When I try to import it into app.module.ts

/* root/src/app/app.module.ts */
import { NgModule } from '@angular/core';
// (other imports)
import { ComponentsModule } from '../components';
  imports: [ ComponentsModule ]
export class AppModule {}

I get the error Cannot find module "../components".

However, if I import it like:
import { ComponentsModule } from '../components/components.module.ts';
or change components.module.ts to index.ts then it all works fine.

Why does my original attempt not work? Is there a way to make it work that way?

This looks like FMTEYEWTK about module resolution.

1 Like

Thanks for the link, it helped a bunch.
I learned the app was looking in '../components' for components.ts which obviously doesn’t exist, and to get it to import components.module.ts I had to import from '../components.module';
The “How TypeScript resolves modules” section of the link also sated my curiosity as to why it was loading index.ts.