question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error : Multiple root routing modules found with nx workspace project

See original GitHub issue

I am testing guess-parser in my nx repo https://github.com/xmlking/yeti I am using guess-parser v0.4.14

var guess_parser = require("guess-parser");
var routes = [];
try {
    // routes = guess_parser.parseAngularRoutes('webapp').map(r => r.path);
    routes = guess_parser.parseAngularRoutes('./apps/webapp/src/app').map(r => r.path);
    console.log(routes);
}
catch (e) {
    console.log('error', e);
}

How to reproduce

git clone https://github.com/xmlking/yeti.git
yarn install
node node guess-parser-test.js

Getting following error for parseAngularRoutes('./apps/webapp/src/app')

node guess-parser-test.js
error TypeError: Cannot read property 'eagerRoutes' of undefined
    at collectRoutingModules (/Users/schintha/Developer/Work/SPA/yeti/node_modules/guess-parser/dist/guess-parser/index.js:465:17)
    at processLazyRoute (/Users/schintha/Developer/Work/SPA/yeti/node_modules/guess-parser/dist/guess-parser/index.js:463:9)
    at Array.forEach (<anonymous>)
    at collectRoutingModules (/Users/schintha/Developer/Work/SPA/yeti/node_modules/guess-parser/dist/guess-parser/index.js:466:28)
    at Object.exports.parseRoutes [as parseAngularRoutes] (/Users/schintha/Developer/Work/SPA/yeti/node_modules/guess-parser/dist/guess-parser/index.js:598:9)
    at Object.<anonymous> (/Users/schintha/Developer/Work/SPA/yeti/guess-parser-test.js:6:27)
    at Module._compile (internal/modules/cjs/loader.js:1139:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
    at Module.load (internal/modules/cjs/loader.js:988:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)

Getting following error for parseAngularRoutes('webapp')

node guess-parser-test.js
error Error: Multiple root routing modules found /Users/schintha/Developer/Work/SPA/yeti/apps/webapp/src/app/app.module.ts, /Users/schintha/Developer/Work/SPA/yeti/libs/admin/src/lib/admin.module.ts, /Users/schintha/Developer/Work/SPA/yeti/libs/blog/src/lib/blog.module.ts, /Users/schintha/Developer/Work/SPA/yeti/libs/dashboard/src/lib/dashboard.module.ts, /Users/schintha/Developer/Work/SPA/yeti/libs/home/src/lib/home.module.ts, /Users/schintha/Developer/Work/SPA/yeti/libs/not-found/src/lib/not-found.module.ts
    at findRootModule (/Users/schintha/Developer/Work/SPA/yeti/node_modules/guess-parser/dist/guess-parser/index.js:434:15)
    at Object.exports.parseRoutes [as parseAngularRoutes] (/Users/schintha/Developer/Work/SPA/yeti/node_modules/guess-parser/dist/guess-parser/index.js:598:31)
    at Object.<anonymous> (/Users/schintha/Developer/Work/SPA/yeti/guess-parser-test.js:5:27)
    at Module._compile (internal/modules/cjs/loader.js:1139:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
    at Module.load (internal/modules/cjs/loader.js:988:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

Ref: https://github.com/scullyio/scully/issues/40

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JandroMejia97commented, Feb 21, 2020

@mgechev I get the same problem in Angular 9:

(node:9412) UnhandledPromiseRejectionWarning: Error: Multiple root routing modules found C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\src\app\home\home-routing.module.ts, C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\src\app\contact\contact-routing.module.ts, C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\src\app\about\about-routing.module.ts, C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\src\app\product\product-routing.module.ts, C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\src\app\order\order-routing.module.ts, C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\src\app\auth\auth-routing.module.ts, C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\src\app\app.module.ts
    at findRootModule (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\guess-parser\dist\guess-parser\index.js:444:15)
    at Object.exports.parseRoutes (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\guess-parser\dist\guess-parser\index.js:622:31)
    at exports.parseRoutes (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\guess-parser\dist\guess-parser\index.js:867:28)
    at Object.routeProvider (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\extend.webpack.config.js:13:16)
    at extractRoutes (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\guess-webpack\dist\guess-webpack\main.js:457:39)
    at GuessPlugin._execute (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\guess-webpack\dist\guess-webpack\main.js:490:9)
    at C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\guess-webpack\dist\guess-webpack\main.js:486:54
    at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:12:1)
    at AsyncSeriesHook.lazyCompileHook (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\tapable\lib\Hook.js:154:20)
    at Compiler.emitAssets (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\webpack\lib\Compiler.js:491:19)
    at onCompiled (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\webpack\lib\Compiler.js:278:9)
    at C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\webpack\lib\Compiler.js:681:15
    at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\tapable\lib\Hook.js:154:20)
    at C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\webpack\lib\Compiler.js:678:31
    at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\aleja\OneDrive\Documents\Cursos\Angular\platzi-store\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:20:1)
(node:9412) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)     
(node:9412) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

extend.webpack.config.js file:

const { GuessPlugin } = require('guess-webpack');
const { parseRoutes } = require('guess-parser');

module.exports = {
  plugins: [
    new GuessPlugin({
      GA: '<GA ID>',
      runtime: {
        delegate: false
      },
      routeProvider() {
        return parseRoutes('.');
      }
    })
  ]
};

The problem is that I have the following URLs in the Routings of each module

app-routing.module.ts

const routes: Routes = [
  {
    path: '',
    component: LayoutComponent,
    children: [
      {
        path: '',
        redirectTo: 'home',
        pathMatch: 'full',
      },
      {
        path: 'home',
        loadChildren: () => import('./home/home.module').then(h => h.HomeModule),
        data: { preload: true }
      },
      {
        path: 'contact',
        loadChildren: () => import('./contact/contact.module').then(c => c.ContactModule),
        data: { preload: true }
      },
      {
        path: 'about',
        loadChildren: () => import('./about/about.module').then(c => c.AboutModule)
      },
      {
        path: 'products',
        loadChildren: () => import('./product/product.module').then(p => p.ProductModule),
        data: { preload: true }
      },
      {
        path: 'orders',
        loadChildren: () => import('./order/order.module').then(o => o.OrderModule)
      },
      {
        path: 'auth',
        loadChildren: () => import('./auth/auth.module').then(a => a.AuthModule)
      }
    ]
  },
  {
    path: 'admin',
    canActivate: [AdminGuard],
    loadChildren: () => import('./admin/admin.module').then(a => a.AdminModule)
  },
  {
    path: '**',
    component: PageNotFoundComponent
  }
];

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

contact-routing.module.ts

const routes: Routes = [
  {
    path: '',
    component: ContactComponent
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class ContactRoutingModule { }

auth-routing.module.ts

const routes: Routes = [
  {
    path: '',
    component: AuthContainer
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class AuthRoutingModule { }

And similar routes in home, product, about and order routing modules. Repository: Platzi Store

0reactions
xmlkingcommented, Feb 3, 2020

@mgechev Just F.Y.I… v0.4.15 causing Multiple root routing modules found error with nx workspace projects v0.4.14 works fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

scullyio/community - Gitter
I just pushed the ng-lib-v8 an tried it on my system, no errors. ... We did not find an empty route ({path:'', component:rootComponent})...
Read more >
Error: More than one module matches. Use skip-import option ...
Show activity on this post. There are two ways to solve this issue. 1) Skip (using --skip-import in command) default import and create ......
Read more >
Project Configuration - Nx
Both package.json and project.json files are located in each project's folder. Nx merges the two files to get each project's configuration.
Read more >
Getting started with standalone components - Angular
Standalone components provide a simplified way to build Angular applications. Standalone components, directives, and pipes aim to streamline the authoring ...
Read more >
Combining Multiple Angular Applications into a Single One
This probably looks like what you expect from an Angular project: ... Open up the app routing module and find the routes constant:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found