On prerendered pages, Webpack injects async <script> that requires webpackJsonp to be defined
See original GitHub issueI have a vue 1.x application that is using prerender-spa-plugin
. When generating the index.html
files for each route on build, webpack
will sometimes inject <script src="/static/js/0.[hash].js" async=""></script>
into the <head></head>
.
This is normal and expected, as webpack optimizes for loading additional chunks on-demand.
A problem surfaces when visiting the endpoint, because the browser tries tries to evaluate the script 0.[hash].js
before manifest.js
or vendor.js
chunks, and reliably causes an exception:
Uncaught ReferenceError: webpackJsonp is not defined.
Is there a flag or option to temporarily prevent webpack
from injecting on-demand chunks? Or must we get hacky and scrub the <script />
tags from prerendered indexes? I cannot naively set the captureAfterTime: 0
, as I rely on other aspects of the page asynchronously rendering.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:10 (3 by maintainers)
Top GitHub Comments
@drewlustro Assuming you are using the
HtmlWebpackPlugin
and as an alternative, you can setinject: 'head'
for the plugin to add all of your scripts (manifest, vendor, and app) into the<head>
. Webpack will place it’sasync
script right after yours, which will make the app work. If you end up using this, as I have, you’ll also probably want to put your initialnew Vue(
inside adocument.addEventListener('DOMContentLoaded', () => {
, since the script in the head will run before the DOM is loaded.Actually, the solution is easy , just go where u added the spa prerender plugin, and add ignoreJSErrors: true: new PrerenderSpaPlugin( // Path to compiled app path.join(__dirname, ‘…/dist’), // List of endpoints you wish to prerender [ ‘/’],{ ignoreJSErrors: true } )