Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Prerender Unable to extract routes from application.  #1769

Closed

Description

@pradeekumar

When I am trying to run "npm run prerender" without lazy-routing it's working but when I am trying with lazy-routing it's giving me ERORR Unable to extract routes from application.

Working with

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

Not working with this

const routes: Routes = [ { path: '', loadChildren: () => import('./home/home.module').then(m => m.HomeModule) } ];

Activity

  1. wagnermaciel commented on Aug 14, 2020

    @wagnermaciel
    Contributor

    @alan-agius4 If I remember correctly, the prerenderer just uses guess-parser to guess routes.

    @pradeekumar If the prerenderer isn't picking up the routes, you can always add it using the "routes" option or even the "routesFile" option if you have a lot of routes

  2. alcfeoh commented on Sep 12, 2020

    @alcfeoh

    @wagnermaciel Where can we configure such "routes" and "routesFile" options? Is it in angular.json?

  3. wagnermaciel commented on Sep 12, 2020

    @wagnermaciel
    Contributor

    @alcfeoh Yep. If you have already run ng add @nguniversal/express-engine, it should be located at the bottom of angular.json. By default it looks like this

    "prerender": {
              "builder": "@nguniversal/builders:prerender",
              "options": {
                "browserTarget": "something:build:production",
                "serverTarget": "something:server:production",
                "routes": [
                  "/"
                ]
              },
              "configurations": {
                "production": {}
              }
            }

    You can switch out "routes" for "routesFile" and give it the relative path to a file with newline separated routes instead of an array. E.g.

      "routesFile: "./routes.txt",
  4. pradeekumar commented on Sep 15, 2020

    @pradeekumar
    Author

    @wagnermaciel I tried with routerFile It still gives the same error. It is not working with shared modules. so I removed the dependencies of shared modules, now it's working.

  5. wagnermaciel commented on Sep 15, 2020

    @wagnermaciel
    Contributor

    @pradeekumar As I mentioned earlier, I believe the issue is with guess-parser but without more details it is difficult to know for sure. If you are manually specifying all of the routes you'd like to prerender you can disable guess-parser by adding "guessRoutes": false to your angular.json.

  6. alcfeoh commented on Sep 15, 2020

    @alcfeoh

    @wagnermaciel This works for me. But still, is there any way we could provide/use a better route parser that works with lazy-loaded modules?

  7. wagnermaciel commented on Sep 16, 2020

    @wagnermaciel
    Contributor

    @alcfeoh Using or providing a custom route parser is not currently supported. I can point you to the function in our code that handles route extraction, which you can modify if you choose to fork the repo

    export async function getRoutes(

    Alternatively, you could use a custom route parser and write it's output to a routesFile

  8. jmartinpersonal commented on Oct 7, 2020

    @jmartinpersonal

    I am having an issue that seems similar. Setting the "guessRoutes": false fixed the initial error but I also get:
    Prerendering 9 route(s) to C:\development\blog-universal\dist\blog-universal\browser
    An unhandled exception occurred: spawn ENAMETOOLONG
    See "C:\Users\jeffm\AppData\Local\Temp\ng-NwusJ7\angular-errors.log" for further details.
    npm ERR! code ELIFECYCLE
    npm ERR! syscall spawn
    npm ERR! file C:\WINDOWS\system32\cmd.exe
    npm ERR! errno ENOENT
    npm ERR! [email protected] prerender: ng run blog-universal:prerender
    npm ERR! spawn ENOENT
    npm ERR!
    npm ERR! Failed at the [email protected] prerender script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR! C:\Users\jeffm\AppData\Roaming\npm-cache_logs\2020-10-07T15_57_06_582Z-debug.log.
    Not finding much information, any help would be appreciated

  9. wagnermaciel commented on Oct 7, 2020

    @wagnermaciel
    Contributor

    @jmartinpersonal That seems unrelated. Seems like there's a file you're trying to prerender with a really long name and NodeJS is freaking out when we try to do an operation with it.

    This might be more what you're looking for

  10. jmartinpersonal commented on Oct 7, 2020

    @jmartinpersonal

    @jmartinpersonal That seems unrelated. Seems like there's a file you're trying to prerender with a really long name and NodeJS is freaking out when we try to do an operation with it.

    This might be more what you're looking for

    I don't think so as this is my routesFile:
    /category/26
    /category/28
    /category/29
    /category/30
    /category/31
    /category/32
    /category/33
    /category/35
    /category/38

  11. wagnermaciel commented on Oct 7, 2020

    @wagnermaciel
    Contributor

    My best guess is that the issue would be with the absolute path to those files

    const routesFilePath = path.join(workspaceRoot, options.routesFile);

  12. added
    need: more info
    on Oct 28, 2020
  13. alan-agius4 commented on Oct 28, 2020

    @alan-agius4
    Collaborator

    @jmartinpersonal, can you kindly provide the contents of the angular-errors log file? Thanks.

  14. jmartinpersonal commented on Oct 28, 2020

    @jmartinpersonal
  15. alan-agius4 commented on Oct 28, 2020

    @alan-agius4
    Collaborator

    This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?

    You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

    This might be related to your directory structure so its really important to get an accurate repro to diagnose this.

  16. added
    need: repro steps
    and removed
    need: more info
    on Oct 28, 2020
  17. vugar005 commented on Dec 12, 2021

    @vugar005

    Hi, I have exactly same issue. @alan-agius4 ,I have example repro.
    You can also see the PR, how universal was added.
    I have created new branch project then added universal via ng add @nguniversal/express-engine
    Thanks in advance.

  18. added
    need: investigation
    and removed
    need: repro steps
    on Dec 12, 2021
  19. vugar005 commented on Dec 12, 2021

    @vugar005

    @alan-agius4 one thing I noticed and can be helpful is when you use lazy loading and also by mistake you also include that lazy module in AppModule, prerender will fail to extract routes. From above repository, if you remove AboutModule from AppModule it would work. Not sure other folks have same problem. I think it should be also handled in this scenario or better error output message or included in documentation. Thanks.

  20. pradeekumar commented on Dec 19, 2021

    @pradeekumar
    Author

    This issue is resolved in the latest version

    I suggest to all upgrading angular to the latest version.

  21. Mersal-Mohamed commented on Dec 29, 2021

    @Mersal-Mohamed

    @pradeekumar i am using latest of Angular and still have the same issue

  22. angular-automatic-lock-bot commented on Jan 29, 2022

    @angular-automatic-lock-bot

    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.

  23. locked and limited conversation to collaborators on Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: buildersneed: investigation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions