Angular-cli: Multiple modules throwing Multiple files found error.

Created on 27 Sep 2016  路  12Comments  路  Source: angular/angular-cli

Please provide us with the following information:

  1. OS && Version
    Mac OSX El Capitan
    angular-cli: 1.0.0-beta.15
    node: 6.6.0
    os: darwin x64
  2. Repro steps. Was this an app that wasn't created using the CLI? What change did you
    do on your code? etc.
    I have a module that is exporting all of my component modules (vdl.module.ts) and another module(app.module.ts) that is actually my bootstrapped demo app. index.ts is only pointing to the app.module. The demo of the component library uses the app.module. Trying to run ng serve throws the below error.
  3. The log given by the failure.
Error locating module for declaration
聽聽聽聽聽聽聽聽SilentError: Multiple module files found: 
  1. I think most component libraries will follow this pattern is there a way to get around the error?

Most helpful comment

Looking at the code, it looks like you need to put vdl.module.ts in a separate folder. app.module.ts should be the only module in the root src directory, other modules should be in a separate folder named after the module.

All 12 comments

Looking at the code, it looks like you need to put vdl.module.ts in a separate folder. app.module.ts should be the only module in the root src directory, other modules should be in a separate folder named after the module.

Update to beta.16 and you should be good to go.

I was having the same issue when trying to generate a new component from root folder.
In my case, the modules were:

  • app.module.ts
  • app-routing.module.ts
    both generated by the cli, and located in src/app ...

After updating (see how here ), it now works as expected without having to move the additionnal module file in separate folder.

@tinesoft I'm on beta-21 and I want to do exactly what you said: in the _src_ directory I want to have:

  • app.module.ts
  • app-router.module.ts

I can't. When I'm trying to generate a new component, I get an error

Error locating module for declaration
    SilentError: Multiple module files found: 

Hi @Olgagr ,

Did you upgrade to beta-21 from a previous version of the cli?
if yes, make sure you followed steps provided in the Updating Angular-CLI Guide .

A quick look your in file: <YOUR_PROJECT_FOLDER>/node_modules /angular-cli/package.json can confirm that you are indeed using the right version of the cli (and not still referencing an old one with the bug).

@tinesoft Thanks for answer. I think I'm using correct version:

In my project folder:

ng version
angular-cli: 1.0.0-beta.21
node: 6.8.1
os: darwin x64

In my project folder/node_modules/angular-cli/package.json:

"version": "1.0.0-beta.21"

That's weird,

Can you post your app.module.ts and app-router.module.ts files?
Also, beta-22-1 is out since a few hours, maybe you can give it a try.

@tinesoft Sure. These are my modules:

app.module.ts

import
{ BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { StoreModule } from "@ngrx/store";

import { AppComponent } from './app.component';
import { LoginComponent } from './public-pages/login/login.component';
import { AuthService } from "./common/services/auth.service";
import { rootReducer } from "./common/reducers/root.reducer";
import { StoreDevtoolsModule } from "@ngrx/store-devtools";
import { ApiHttpService } from "./common/services/api-http.service";
import { CompaniesComponent } from './companies/companies.component';
import { AppRouterModule } from "./app-router.module";

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    CompaniesComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    HttpModule,
    StoreModule.provideStore(rootReducer),
    StoreDevtoolsModule.instrumentOnlyWithExtension(),
    AppRouterModule
  ],
  providers: [AuthService, ApiHttpService],
  bootstrap: [AppComponent]
})
export class AppModule { }

app-router.module.ts

import {NgModule} from "@angular/core";
import {Routes, RouterModule} from "@angular/router";
import {LoginComponent} from "../public-pages/login/login.component";
import {CompaniesComponent} from "../companies/companies.component";

const routes: Routes = [
  {path: '', pathMatch: 'full', component: LoginComponent},
  {path: 'companies', component: CompaniesComponent}
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
  providers: []
})
export class AppRouterModule {}

They are pretty basic, to my mind.

I'll also try beta-22-1 as you recommend.

@tinesoft Ok, I know what is going on. I've checked @bonnici referenced to and it looks like my router module has to be in file called routing.module.ts. When I changed the file name, I didn't have problems with generating component any more. I think this is not obvious. Do we have any docs about it ? Maybe we should add it ?

I did notice you called your routing file app-router.module.ts instead of app-routing.module.ts as illustrated in most Angular Routing-related docs & examples on angular.io, but i never thought that could be the issue...

Good to know!

Maybe this will no longer matter when generating Routing from the CLI is re-activated again, as the tool with take care of naming the file appropriately.

This issue is happening to me all of a sudden in my project https://github.com/MohamadAtieh/angular2-dash

I am not sure why, but I can't generate anything although I was able to before. I have two modules in the app directory, but they are named differently (app.module.ts and nav.module.ts)

I think this happened to me after adding the nav.module.ts as this was the last thing generated by the cli.

Edit:

That was fixed when nav.module.ts was moved to another directory

That's what I was about to recommend you!

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings