universal: Prerender Unable to extract routes from application.

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) } ];

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 19 (6 by maintainers)

Most upvoted comments

@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",

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! blog-universal@0.0.0 prerender: ng run blog-universal:prerender npm ERR! spawn ENOENT npm ERR! npm ERR! Failed at the blog-universal@0.0.0 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

@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.

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.