question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[prerender-spa-plugin] Unable to prerender all routes! when upgrade webpack to v5+

See original GitHub issue

ERROR in [prerender-spa-plugin] Unable to prerender all routes! this happened in webpack5, but work well in webpack4

node env: v12.18.2

error messages comes out with deeply debug; image

image image

webpack5 breaked here because of this:

https://webpack.js.org/blog/2020-10-10-webpack-5-release/#filesystems

Filesystems Next to compiler.inputFileSystem and compiler.outputFileSystem there is a new compiler.intermediateFileSystem for all fs actions that are not considered as input or output, like writing records, cache or profiling output.

The filesystems have now the fs interface and do no longer demand additional methods like join or mkdirp. But if they have methods like join or dirname they are used.

code update here to be compatible with both webpack4/5

  // From https://github.com/ahmadnassri/mkdirp-promise/blob/master/lib/index.js
  const mkdirp = function (dir, opts) {
    return new Promise((resolve, reject) => {
      console.log('\ndir', dir, opts, '\n');
      try {
        compilerFS.mkdirp(dir, opts, (err, made) => err === null ? resolve(made) : reject(err))
      } catch(e) {
        compilerFS.mkdir(dir, opts, (err, made) => err === null ? resolve(made) : reject(err))
      }
    })
  }

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:11
  • Comments:10

github_iconTop GitHub Comments

12reactions
dreysolanocommented, Feb 13, 2021

For anyone interested, I forked the main project and created the following package which has the fix noted above for Webpack 5, along with up-to-date dependencies. Hopefully this can be PRed back into the main project repo if/when @chrisvfritz and team start supporting again.

https://www.npmjs.com/package/@dreysolano/prerender-spa-plugin

9reactions
dreysolanocommented, Feb 9, 2021

Nice find all. One caveat is that the above will not work for nested routes such as /pages/about-us if the /pages dir does not already exist. The solution here is to pass {recursive: true} in the opts param. This solved the issue for me:

compilerFS.mkdir(dir, {...opts, recursive: true}, (err, made) => err === null ? resolve(made) : reject(err))

@chrisvfritz - any chance that this project will be supported again soon? I’m sure a number of us in the community would be happy to lend a hand!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix [prerender-spa-plugin] Unable to prerender all routes
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...
Read more >
[prerender-spa-plugin] Unable to prerender all ... - Bountysource
ERROR in [prerender-spa-plugin] Unable to prerender all routes! this happened in webpack5, but work well in webpack4. node env: v12.18.2.
Read more >
ERROR [prerender-spa-plugin] - Unable to prerender all routes
ok I fixed the problem by rendering less pages. It seems there is a problem with a poor connection, which in my case...
Read more >
single-prerender-spa-plugin - npm package | Snyk
All security vulnerabilities belong to production dependencies of direct and indirect packages. License: MIT. Security Policy: No.
Read more >
To v5 from v4 - webpack
Upgrade all used Plugins and Loaders to the latest available version ... since latest version might only support webpack 5 and will fail...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found