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)
}
];
@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
@wagnermaciel Where can we configure such "routes" and "routesFile" options? Is it in angular.json?
@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.
```json
"routesFile: "./routes.txt",
````
@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.
@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.
@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?
@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
Alternatively, you could use a custom route parser and write it's output to a routesFile
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
@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.
@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.
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
My best guess is that the issue would be with the absolute path to those files
@jmartinpersonal, can you kindly provide the contents of the angular-errors log file? Thanks.
Thank you for your response. I have determined the error was unrelated to this post.
From: Alan Agius notifications@github.com
Sent: Wednesday, October 28, 2020 8:59 AM
To: angular/universal universal@noreply.github.com
Cc: Jeff Martin jeffm@mhginsurance.com; Mention mention@noreply.github.com
Subject: Re: [angular/universal] Prerender Unable to extract routes from application. (#1769)
@jmartinpersonalhttps://github.com/jmartinpersonal, can you kindly provide the contents of the log file?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/angular/universal/issues/1769#issuecomment-717915382, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKGTHCXNPUYTI2X3C4JHR4LSNAIQ7ANCNFSM4O7Y7AFQ.
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.
Most helpful comment
@alcfeoh Yep. If you have already run
ng add @nguniversal/express-engine, it should be located at the bottom ofangular.json. By default it looks like thisYou 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.```json
"routesFile: "./routes.txt",
````