Scully: Multiple root routing modules found

Created on 2 Feb 2020  ·  18Comments  ·  Source: scullyio/scully

🐞 Bug report

Description

latest scullyio cause following error

Reproduce : https://github.com/xmlking/yeti

yarn run scully --project webapp --showGuessError

```
yarn run scully --project webapp --showGuessError
yarn run v1.21.1
$ scully --project webapp --showGuessError

☺ new Angular build imported
☺ Started servers in background
servers available
Finding all routes in application.
We could not find "apps/webapp/tsconfig.app.json/tsconfig.app.json". Using the apps source folder as source. This might lead to unpredictable results
Error: Multiple root routing modules found /Users/schintha/Developer/Work/SPA/yeti/libs/blog/src/lib/blog.module.ts, /Users/schintha/Developer/Work/SPA/yeti/apps/webapp/src/app/app.module.ts
at findRootModule (/Users/schintha/Developer/Work/SPA/yeti/node_modules/guess-parser/dist/guess-parser/index.js:444:15)
at Object.exports.parseRoutes [as parseAngularRoutes] (/Users/schintha/Developer/Work/SPA/yeti/node_modules/guess-parser/dist/guess-parser/index.js:622:31)
at Object.exports.traverseAppRoutes (/Users/schintha/Developer/Work/SPA/yeti/node_modules/@scullyio/scully/routerPlugins/traverseAppRoutesPlugin.js:21:37)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Object.exports.generateAll (/Users/schintha/Developer/Work/SPA/yeti/node_modules/@scullyio/scully/utils/defaultAction.js:32:31)
at async Promise.all (index 0)

We encountered a problem while reading the routes from your applications source.
This might happen when there are lazy-loaded routes, that are not loaded,
Or when there are paths we can not resolve statically.
Check the routes in your app, rebuild and retry.
(You can inspect the error by passing the --showGuessError flag

When there are extraRoutes in your config, we will still try to render those.

We did not find an empty route ({path:'', component:rootComponent}) in your app.
This means that the root of your application will be you normal angular app, and
is not rendered by Scully
In some circumstances this can be cause because a redirect like:
({path: '', redirectTo: 'home', pathMatch: 'full'})
is not picked up by our scanner.

By adding '' to the extraRoutes array in the scully.config option, you can bypass this issue

No routes found in application, are you sure you installed the router? Terminating.
error Command failed with exit code 15.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```

bug need more info need repo example

Most helpful comment

I'm not sure if the following should go inside this thread, and I'm new to contributing, but I struggled with Scully not finding my routes and generating just the root index.html, I got the same message

We encountered a problem while reading the routes from your applications source.
This might happen when there are lazy-loaded routes, that are not loaded,
Or when there are paths we can not resolve statically.
Check the routes in your app, rebuild and retry.

But after adding the --showGuessError flag, the error differed, and I got something like:

loadChildren.split is not a function

Before continuing I want to clarify that my project has nested lazy loading for some parts, and because of that I couldn't locate the error at first because apparently all my routes inside app-routing.module.ts where correct, but the problem as I later discovered was that some of the nested routes were relative to the folder which caused the problem.

After I changed the loading of the modules to something like:

{
  path: "<route>",
  loadChildren: () => ("src/app/.../<name>.module.ts).then(m=>m.<ModuleName>)
}

the error disappeared and Scully was able to find all the modules and routes correctly.

I hope this helps anyone that stumbles onto a similar problem

All 18 comments

@xmlking Your projectRoot is pointing to a non-existing path. As projectRoot is optional now, you should remove it.
However, that does not solve your issue. I have taken a look at it, and it seems to be an issue with the guess-parser we use. To solve this I need a minimal reproduction of the issue. By that I mean a small demo project, just using angular, NX and Scully. I tried to build that, but could not reproduce your issue that way.

hi @SanderElias please check issue https://github.com/guess-js/guess/issues/315
you can use my repo for testing. my readme page has steps i used to reproduce.
https://github.com/xmlking/yeti thanks for new features

b.t.w, workaround ~projectRoot: './apps/webapp/tsconfig.app.json' was working find until recent scully change.

@xmlking Yes, that isn't needed anymore. But I don't know what currently goes haywire in your project, I really need the problem isolated. the tsconfig.app.json is now automatically used.

A second thought, can you try a somewhat older version off the guess-parser?

will try tomorrow

Interestingly after I locked guess-parser version to 0.4.14 package.json, guess part works but got Puppeteer errors.
it fails __very__ quickly but noticed scully server running in the background @
http://localhost:1864/home/blog/blog-3

package.json

  "resolutions": {
    "guess-parser": "0.4.14"
  }
yarn run scully --project webapp
yarn run v1.21.1
$ scully --project webapp

 ☺   new Angular build imported
 ☺   Started servers in background
servers available
Finding all routes in application.


We did not find an empty route ({path:'', component:rootComponent}) in your app.
This means that the root of your application will be you normal angular app, and
is not rendered by Scully
In some circumstances this can be cause because a redirect like:
   ({path: '', redirectTo: 'home', pathMatch: 'full'})
is not picked up by our scanner.

By adding '' to the extraRoutes array in the scully.config option, you can bypass this issue


Pull in data to create additional routes.
Finding files in folder "/Users/schintha/Developer/Work/SPA/yeti/libs/blog/posts"
Route list created in files:
  "/Users/schintha/Developer/Work/SPA/yeti/apps/webapp/src/assets/scully-routes.json",
  "/Users/schintha/Developer/Work/SPA/yeti/dist/static/apps/webapp/assets/scully-routes.json",
  "/Users/schintha/Developer/Work/SPA/yeti/dist/apps/webapp/assets/scully-routes.json"

Puppeteer error while rendering "/home/blog/2019-07-progressive-web-app" Error: net::ERR_CONNECTION_REFUSED at http://localhost:1864/home/blog/2019-07-progressive-web-app
Puppeteer error while rendering "/dashboard" Error: net::ERR_CONNECTION_REFUSED at http://localhost:1864/dashboard
Puppeteer error while rendering "/home/blog" Error: net::ERR_CONNECTION_REFUSED at http://localhost:1864/home/blog
Puppeteer error while rendering "/home/login" Error: net::ERR_CONNECTION_REFUSED at http://localhost:1864/home/login
Puppeteer error while rendering "/home" Error: net::ERR_CONNECTION_REFUSED at http://localhost:1864/home
Puppeteer error while rendering "/admin" Error: net::ERR_CONNECTION_REFUSED at http://localhost:1864/admin
Puppeteer error while rendering "/home/blog/2019-11-ngx-semantic-version" Error: net::ERR_CONNECTION_REFUSED at http://localhost:1864/home/blog/2019-11-ngx-semantic-version
Puppeteer error while rendering "/404" Error: net::ERR_CONNECTION_REFUSED at http://localhost:1864/404
Puppeteer error while rendering "/home/blog/blog-2" Error: net::ERR_CONNECTION_REFUSED at http://localhost:1864/home/blog/blog-2
Puppeteer error while rendering "/dashboard" Error: net::ERR_CONNECTION_REFUSED at http://localhost:1864/dashboard
error Command failed with exit code 15.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

should I still add IdleMonitorService ? Still see in ng-add

couple of findings

  1. "guess-parser": "0.4.15" will break nx compatibility again. it works when lock to version 0.4.14
  2. my Puppeteer error are caused due to failed scully command and dangling server running on port 1864 in the background.

After killing (lsof -nP +c 15 | grep LISTEN) the background server, I was able to build with scully build successfully.
why we have to run scully in the background? we may have to prioritize this issue as developers will be spending more time debugging without knowing about possible __zombie__ hanging server

We have npx scully killServer to kill the 'zombie' server. (actually, the server just keeps on working, and makes next iterations of Scully faster)
But I will talk with @jorgeucano later on, and we will make sure we kill the server properly when Scully ends

@xmlking To be able to work on the guess issue, I still need the problem in an isolated reproduction

any nx created monorepo with couple of lazy loaded modules can reproduce the above error.
my test nx project can be used https://github.com/xmlking/yeti
to reproduce change in package.json

  "resolutions": {
    "guess-parser": "0.4.15"
  }
# build angular
ng build
# build scully blog
yarn run scully --project webapp
# serve static content
yarn run lite-server

@xmlking I just created a fresh Nx monorepo, and added Scully. Worked without a problem. When you want us to investigate this more in-depth, we need a bare minimum reproduction repository. With _only_ Nx, Scully, and Angular.

@SanderElias wonder if you tried any lazy-loaded child modules or just default app?
there is no use testing default generated app. this problem is related to having lazy-loaded modules under libs in nx workspace
if possible please share your test app. Thanks

@xmlking I had a lazy route in there, As everything was working I deleted the thing.
Not sure I had a lazy lib. As I'm not using NX myself, I'm probably the wrong person to create a repro anyway.

Closing for now, by lack of actionable things. Will reopen when a minimal reproduction is available

@xmlking I experience the same issue in my Nx Workspace. Did you find a solution?

I'm not sure if the following should go inside this thread, and I'm new to contributing, but I struggled with Scully not finding my routes and generating just the root index.html, I got the same message

We encountered a problem while reading the routes from your applications source.
This might happen when there are lazy-loaded routes, that are not loaded,
Or when there are paths we can not resolve statically.
Check the routes in your app, rebuild and retry.

But after adding the --showGuessError flag, the error differed, and I got something like:

loadChildren.split is not a function

Before continuing I want to clarify that my project has nested lazy loading for some parts, and because of that I couldn't locate the error at first because apparently all my routes inside app-routing.module.ts where correct, but the problem as I later discovered was that some of the nested routes were relative to the folder which caused the problem.

After I changed the loading of the modules to something like:

{
  path: "<route>",
  loadChildren: () => ("src/app/.../<name>.module.ts).then(m=>m.<ModuleName>)
}

the error disappeared and Scully was able to find all the modules and routes correctly.

I hope this helps anyone that stumbles onto a similar problem

Was this page helpful?
0 / 5 - 0 ratings