You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 22, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 22, 2024. It is now read-only.
Prerender Unable to extract routes from application. #1769
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.
@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
@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
@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.
@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
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
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.
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.
@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.
Activity
wagnermaciel commentedon Aug 14, 2020
@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
alcfeoh commentedon Sep 12, 2020
@wagnermaciel Where can we configure such "routes" and "routesFile" options? Is it in
angular.json?wagnermaciel commentedon Sep 12, 2020
@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.pradeekumar commentedon Sep 15, 2020
@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.
wagnermaciel commentedon Sep 15, 2020
@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": falseto yourangular.json.alcfeoh commentedon Sep 15, 2020
@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?
wagnermaciel commentedon Sep 16, 2020
@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
universal/modules/builders/src/prerender/utils.ts
Line 21 in cd9ee41
Alternatively, you could use a custom route parser and write it's output to a
routesFilejmartinpersonal commentedon Oct 7, 2020
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:prerendernpm 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
wagnermaciel commentedon Oct 7, 2020
@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
jmartinpersonal commentedon Oct 7, 2020
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
wagnermaciel commentedon Oct 7, 2020
My best guess is that the issue would be with the absolute path to those files
universal/modules/builders/src/prerender/utils.ts
Line 29 in cd9ee41
alan-agius4 commentedon Oct 28, 2020
@jmartinpersonal, can you kindly provide the contents of the
angular-errorslog file? Thanks.jmartinpersonal commentedon Oct 28, 2020
alan-agius4 commentedon Oct 28, 2020
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-appand 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.
vugar005 commentedon Dec 12, 2021
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-engineThanks in advance.
vugar005 commentedon Dec 12, 2021
@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 removeAboutModulefromAppModuleit 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.pradeekumar commentedon Dec 19, 2021
This issue is resolved in the latest version
I suggest to all upgrading angular to the latest version.
Mersal-Mohamed commentedon Dec 29, 2021
@pradeekumar i am using latest of Angular and still have the same issue
angular-automatic-lock-bot commentedon Jan 29, 2022
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.