Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnhandledPromiseRejectionWarning: Error: Multiple root routing modules found #87

Closed
keserwan opened this issue Oct 8, 2019 · 20 comments

Comments

@keserwan
Copy link

keserwan commented Oct 8, 2019

I am trying to do npx angular-prerender after I doing a successful ng build

I got this error:
PS C:\Development\xyz\ClientApps> npx angular-prerender
(node:1384) UnhandledPromiseRejectionWarning: Error: Multiple root routing modules found C:\Development\xyz\ClientApps\libs\shared\src\lib\shared-routing.module.ts, C:\Development\xyz\ClientApps\apps\website\src\app\app.module.ts, C:\Development\xyz\ClientApps\libs\about\src\lib\about-routing.module.ts, C:\Development\xyz\ClientApps\libs\agent\src\lib\agent-routing.module.ts, C:\Development\xyz\ClientApps\libs\camp\src\lib\camp-routing.module.ts, C:\Development\xyz\ClientApps\libs\flight\src\lib\flight-routing.module.ts, C:\Development\xyz\ClientApps\libs\game\src\lib\game-routing.module.ts, C:\Development\xyz\ClientApps\libs\giftcard\src\lib\gift-card-routing.module.ts, C:\Development\xyz\ClientApps\libs\home\src\lib\home-routing.module.ts, C:\Development\xyz\ClientApps\libs\profile\src\lib\profile-routing.module.ts, C:\Development\xyz\ClientApps\libs\trip\src\lib\trip-routing.module.ts
at findRootModule (C:\Development\xyz\ClientApps\node_modules\guess-parser\dist\guess-parser\index.js:412:15)
at exports.parseRoutes (C:\Development\xyz\ClientApps\node_modules\guess-parser\dist\guess-parser\index.js:575:31)
at prerender (C:\Development\xyz\ClientApps\node_modules\angular-prerender\build\node\functions\prerender.js:89:54)
(node:1384) 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:1384) [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.

I have 3 angular apps and several libraries, but I tried to prerender the default app.

here are my configurations:
ng --version

 _                      _                 ____ _     ___ 
/ \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|

/ △ \ | '_ \ / | | | | |/ _ | '__| | | | | | |
/ ___ | | | | (
| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/

Angular CLI: 8.3.6
Node: 12.4.0
OS: win32 x64
Angular: 8.2.8
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router, service-worker, upgrade

Package Version

@angular-devkit/architect 0.803.3
@angular-devkit/build-angular 0.803.6
@angular-devkit/build-ng-packagr 0.803.6
@angular-devkit/build-optimizer 0.803.6
@angular-devkit/build-webpack 0.803.6
@angular-devkit/core 8.3.6
@angular-devkit/schematics 8.3.6
@angular/cdk 8.2.2
@angular/cli 8.3.6
@angular/http 7.2.15
@angular/material 8.2.2
@angular/material-moment-adapter 8.2.2
@angular/pwa 0.803.6
@ngtools/webpack 8.3.6
@nguniversal/common 8.1.1
@nguniversal/express-engine 8.1.1
@nguniversal/module-map-ngfactory-loader 8.1.1
@schematics/angular 8.3.6
@schematics/update 0.803.6
ng-packagr 5.5.1
rxjs 6.5.3
typescript 3.5.3
webpack 4.39.2

@chrisguttandin
Copy link
Owner

Hi @keserwan,

thanks for the detailed error report. The error you get comes from the guess-parser package. For some reason it seems to be confused. It tries to identify the root module of your app. And according to the algorithm it uses there is more than one root module.

https://github.com/guess-js/guess/blob/master/packages/guess-parser/src/angular/index.ts#L295

It works by analyzing the dependency tree that's formed by all the NgModules. Every NgModule which is not required by another NgModule is considered a root module. Normally there is only one NgModule which satisfies that constraint. But in your case it looks like it identified the root NgModule of all your libraries as well. Is that possible?

\libs\shared\src\lib\shared-routing.module.ts
\apps\website\src\app\app.module.ts
\libs\about\src\lib\about-routing.module.ts
\libs\agent\src\lib\agent-routing.module.ts
\libs\camp\src\lib\camp-routing.module.ts
\libs\flight\src\lib\flight-routing.module.ts
\libs\game\src\lib\game-routing.module.ts
\libs\giftcard\src\lib\gift-card-routing.module.ts
\libs\home\src\lib\home-routing.module.ts
\libs\profile\src\lib\profile-routing.module.ts
\libs\trip\src\lib\trip-routing.module.ts

I tried to modify the default test case to reproduce the problem. However it seems to be not enough to trigger the error. Can you tell me what else I need to do to link the galaxy library into my universe application?

Here are the commands I used:

npx @angular/cli new universe --create-application=false
cd universe/
ng generate application universe --routing
ng generate universal --client-project universe
ng generate library galaxy
npm install angular-prerender --save-dev
ng build
ng run universe:server
npx angular-prerender

@keserwan
Copy link
Author

keserwan commented Oct 8, 2019

I am using wrapper modules to connect the libraries with the app.
something like this in the app-routing.module.ts

{
path: 'home',
loadChildren: './_wrapper-modules/home-wrapper.module#HomeWrapperModule'
},

and in HomeWrapperModule.ts I am importing the lib:

import { NgModule } from '@angular/core'
import { HomeModule } from '@xyz-xyz-web/home';

@NgModule(
{
imports: [
HomeModule
]
}
)
export class HomeWrapperModule { }

@chrisguttandin
Copy link
Owner

I would assume that the HomeModule is located at \libs\home\src\lib\home.module.ts. Is that correct? Is the NgModule defined in \libs\home\src\lib\home-routing.module.ts imported by the HomeModule?

@keserwan
Copy link
Author

keserwan commented Oct 9, 2019

Yes right, ur assumption is correct.
Sorry I didn't mention the configuration in main tsconfig.json file:

"paths": {
  "moment": [
    "../node_modules/moment/min/moment.min.js"
  ],
  "@xyz-xyz-web/*": ["@xyz-xyz-web/*"],
  "@xyz-xyz-web/utilities": ["libs/utilities/src/index.ts"],
  "@xyz-xyz-web/shared": ["libs/shared/src/index.ts"],
  "@xyz-xyz-web/material": ["libs/material/src/index.ts"],
  "@xyz-xyz-web/core": ["libs/core/src/index.ts"],
  "@xyz-xyz-web/flight": ["libs/flight/src/index.ts"],
  "@xyz-xyz-web/trip": ["libs/trip/src/index.ts"],
  "@xyz-xyz-web/about": ["libs/about/src/index.ts"],
  "@xyz-xyz-web/agent": ["libs/agent/src/index.ts"],
  "@xyz-xyz-web/camp": ["libs/camp/src/index.ts"],
  "@xyz-xyz-web/game": ["libs/game/src/index.ts"],
  "@xyz-xyz-web/giftcard": ["libs/giftcard/src/index.ts"],
  "@xyz-xyz-web/team": ["libs/team/src/index.ts"],
  "@xyz-xyz-web/home": ["libs/home/src/index.ts"],
  "@xyz-xyz-web/profile": ["libs/profile/src/index.ts"]
}

also here is libs/home/src/index.ts:
export * from './lib/home.module';

Knowing that I followed best practices by Nrwl.

@chrisguttandin
Copy link
Owner

Thanks a lot. I can reproduce the problem now.

I think you ran into two bugs at the same time. guess-parser doesn't handle barrel files so far and it doesn't resolve local links defined as paths in the tsconfig file.

I will try to submit a pull request for guess-parser later today. Once that is merged angular-prerender will hopefully work for you as well.

@keserwan
Copy link
Author

keserwan commented Oct 9, 2019

Thank you @chrisguttandin

@chrisguttandin
Copy link
Owner

Hi @keserwan, v4.1.20 should work now. It requires guess-parser v0.4.9 which contains the fix.

But please double-check if it really works. In case it doesn't please feel free to reopen this issue.

@keserwan
Copy link
Author

Thank you for your support @chrisguttandin,
I installed v4.1.20
Also I did npm i guess-parser --save-dev, it installed version 0.4.9

I am still getting the below error, after doing the following commands:
Please note that, my angular.json has 3 apps and several libraries, so in the dist folder there will be sub folder for each app. I assume the command "npx angular-prerender" is doing the job for the default app in angular.json?

here are the commands I did:
ng build --configuration=production
ng run website:server:production
npx angular-prerender

here is the output:

PS C:\Development\xyz\ClientApps> npx angular-prerender
(node:14520) UnhandledPromiseRejectionWarning: Error: Multiple root routing modules found C:\Development\xyz\ClientApps\libs\shared\src\lib\shared-routing.module.ts, C:\Development\xyz\ClientApps\apps\website\src\app\app-routing.module.ts, C:\Development\xyz\ClientApps\libs\about\src\lib\about-routing.module.ts, C:\Development\xyz\ClientApps\libs\agent\src\lib\agent-routing.module.ts, C:\Development\xyz\ClientApps\libs\camp\src\lib\camp-routing.module.ts, C:\Development\xyz\ClientApps\libs\flight\src\lib\flight-routing.module.ts, C:\Development\xyz\ClientApps\libs\game\src\lib\game-routing.module.ts, C:\Development\xyz\ClientApps\libs\giftcard\src\lib\gift-card-routing.module.ts, C:\Development\xyz\ClientApps\libs\home\src\lib\home-routing.module.ts, C:\Development\xyz\ClientApps\libs\profile\src\lib\profile-routing.module.ts, C:\Development\xyz\ClientApps\libs\trip\src\lib\trip-routing.module.ts
at findRootModule (C:\Development\xyz\ClientApps\node_modules\guess-parser\dist\guess-parser\index.js:419:15)
at exports.parseRoutes (C:\Development\xyz\ClientApps\node_modules\guess-parser\dist\guess-parser\index.js:582:31)
at prerender (C:\Development\xyz\ClientApps\node_modules\angular-prerender\build\node\functions\prerender.js:89:54)
(node:14520) 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:14520) [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.

@chrisguttandin
Copy link
Owner

Thanks for checking it again.

Sadly that error looks very familiar. It's almost the same as the one that we started with. Only the app.module.ts has been replaced by the app-routing.module.ts.

There is no chance for me to access your repo, right? The test case that I build to reproduce the error did work as expected.

@keserwan
Copy link
Author

I prepared a project with the same structure on this repo
I am able to reproduce the issue on it too
https://github.com/keserwan/testAngularPrerender

@chrisguttandin
Copy link
Owner

Thanks a lot. I will take a look.

@chrisguttandin
Copy link
Owner

I made a little mistake in the last pull request. I created another pull request to fix it. guess-js/guess#247

@keserwan
Copy link
Author

Thank you for your contributions!

@chrisguttandin
Copy link
Owner

Hi @keserwan, can you please try it once more with v1.4.21. It does at least work with your demo project.

You can also uninstall guess-parser if you don't use it for anything else. It doesn't need to be an explicit dependency as it is bundled with angular-prerender.

@keserwan
Copy link
Author

Sorry for the late reply, I will check tomorrow and let you know, thank you very much for your contributions

@keserwan
Copy link
Author

Hi @chrisguttandin, I updated angular-prerender to 4.1.21, deleted node-modules & package-lock.json and did the following again:

npm i
npm run build:ssr
npx angular-prerender

Note: I pushed the changes to my demo repo, https://github.com/keserwan/testAngularPrerender

I am getting this error now:

PS C:\Development\test\New folder> npx angular-prerender
(node:2188) UnhandledPromiseRejectionWarning: Error: Multiple root routing modules found C:\Development\test\New folder\apps\website\src\app\app-routing.module.ts, C:\Development\test\New folder\libs\about\src\lib\about-routing.module.ts, C:\Development\test\New folder\libs\camp\src\lib\camp-routing.module.ts, C:\Development\test\New folder\libs\game\src\lib\game-routing.module.ts, C:\Development\test\New folder\libs\home\src\lib\home-routing.module.ts
at findRootModule (C:\Development\test\New folder\node_modules\guess-parser\dist\guess-parser\index.js:419:15)
at exports.parseRoutes (C:\Development\test\New folder\node_modules\guess-parser\dist\guess-parser\index.js:582:31)
at prerender (C:\Development\test\New folder\node_modules\angular-prerender\build\node\functions\prerender.js:89:54)
(node:2188) 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:2188) [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.
PS C:\Development\test\New folder>

@chrisguttandin
Copy link
Owner

Thanks @keserwan, for testing it again. Since you are using a Windows computer you probably ran into the bug reported here: #88. I'll try to fix that now. Sorry for the back and forth.

@chrisguttandin
Copy link
Owner

Hi @keserwan, I just published another patch release. Can you please try once more with version 4.1.22. Many thanks in advance.

@keserwan
Copy link
Author

THANK YOU!
IT WORKED ON WINDOWS.

@chrisguttandin
Copy link
Owner

I'm happy to hear that. Thanks for your patience and thanks again for making me aware of the issue in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants