independent full stack developer

/ Developer's blog

How to fix [prerender-spa-plugin] Unable to prerender all routes

Wednesday, April 24, 2024

How I fixed the prerender error with  [prerender-spa-plugin], it worked yesterday but today not, just try to add a param to your webpack maxConcurrent ...

Hey, if you work with vue-cli and prerender your apps with prerender-spa-plugin, and it worked yesterday, but it doesn't work today - and you got the message Unable to prerender all routes

[prerender-spa-plugin] Unable to prerender all routes!

(node:28824) UnhandledPromiseRejectionWarning: Build failed with errors.
(node:28824) 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(). (rej
ection id: 1)
(node:28824) [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.

Don't panic, keep calm and stop to tweak your webpack config, because probably it's much easier than you think, and the reason for that is a poor connection, try to limit concurrently rendered routes (check maxConcurrentRoutes param), and hope the error will disappear. It happened because if you render a hundred of tabs at the same time with a poor connection, it just throws with a timeout.

 

renderer: new Renderer({
  injectProperty: "__PRERENDER_INJECTED",
  inject: {
    prerendered: false,
  },
  renderAfterElementExists: "[ready]",
  headless: false,
  ignoreHTTPSErrors: true,
  maxConcurrentRoutes: 2,
});

Viola! It helped me, hope you will find it helpful too, if not, check the GitHub issues :)

Cheers, and have a nice day, collegues.

4565 people already saw it