chrisvfritz / prerender-spa-plugin

Prerenders static HTML in a single-page application.
MIT License
7.33k stars 634 forks source link

Unable to prerender all routes! #437

Open nkHub opened 3 years ago

nkHub commented 3 years ago

es6/index.js in webpack5 compilerFS.mkdirp is undefined.

nkHub commented 3 years ago

I install mkdirp package and change index.js the directory of es6 for replace the function mkdirp,after that it works.

evd1ser commented 3 years ago

I install mkdirp package and change index.js the directory of es6 for replace the function mkdirp,after that it works.

Same problem, could you please write more details about the solution?

zenghj commented 3 years ago

I got the same isuue

zenghj commented 3 years ago

There is alreay a merge request to solve this issue here

dmitryuk commented 3 years ago

github:RoboFinance/prerender-spa-plugin#4.0.0

nangezi123 commented 3 years ago

If no network,you must make sure that there is chromium (/node_modules/puppteer/.local-chromium)

Next, you can add console.log('err', err) in catch (/node_modules/prerender-spa-plugin/es6/index.js),you will find details.

// node_modules/prerender-spa-plugin/es6/index.js
...
.catch(err => {
        console.log('err', err) // Add this to find the error at line 144
        PrerendererInstance.destroy()
        const msg = '[prerender-spa-plugin] Unable to prerender all routes!'
        console.error(msg)
        compilation.errors.push(new Error(msg))
        done()
      })

If your error is Navigation Timeout Exceeded: 30000ms exceeded, the following need to be modified:

// node_modules/@prerenderer/renderer-puppeteer/es6/renderer.js
const navigationOptions = (options.navigationOptions) ? { waituntil: 'networkidle0', ...options.navigationOptions } : { waituntil: 'networkidle0' };

await page.goto(`${baseURL}${route}`, navigationOptions);

modify to

await page.goto(`${baseURL}${route}`, {...navigationOptions, timeout: 0});

https://stackoverflow.com/questions/52163547/node-js-puppeteer-how-to-set-navigation-timeout

In webpack, add navigationOptions: { timeout: 0} const PrerenderSpaPlugin = require("prerender-spa-plugin"); const Renderer = PrerenderSpaPlugin.PuppeteerRenderer

new PrerenderSpaPlugin({
        routes: ['/', '/contact'],
        renderer: new Renderer({
             navigationOptions: {
                 timeout: 0
             }
        })
}),
Tofandel commented 2 years ago

Duplicate of https://github.com/chrisvfritz/prerender-spa-plugin/issues/414, not compatible with webpack 5