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.

On prerendered pages, Webpack injects async <script> that requires webpackJsonp to be defined

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
nemtsovcommented, Nov 8, 2016

@drewlustro Assuming you are using the HtmlWebpackPlugin and as an alternative, you can set inject: 'head' for the plugin to add all of your scripts (manifest, vendor, and app) into the <head>. Webpack will place it’s async 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 initial new Vue( inside a document.addEventListener('DOMContentLoaded', () => {, since the script in the head will run before the DOM is loaded.

3reactions
Yami-Bitsharkcommented, Dec 15, 2017

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 } )

Read more comments on GitHub >

github_iconTop Results From Across the Web

webprerender-plugin - npm
Prerendering vs Server-Side Rendering (SSR) · SEO: When content is loaded asynchronously, crawlers won't wait for it to be loaded. · Slow clients: ......
Read more >
webpackJsonp is not defined: webpack-dev-server and ...
And this is my scripts that runs the webpack-dev-server: const webpack =require('webpack'); const WebpackDevServer = require(' ...
Read more >
How to Pre-render Vue.js Powered Websites with webpack
PuppeteerRenderer({ // We need to inject a value so we're able to // detect if the page is currently pre-rendered. The Prerender SPA...
Read more >
prerender-spa-plugin3: Docs, Community, Tutorials | Openbase
Prerender SPA Plugin. Flexible, framework-agnostic static site generation for sites and SPAs built with webpack. npm version npm downloads Dependency Status ...
Read more >
Loader Interface - webpack
Loaders were originally designed to work in synchronous loader pipelines, like Node.js (using enhanced-require), and asynchronous pipelines, like in webpack ...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found