not working when using `vue` with `apollo-client`
I'm not sure who's the guilty one :), but here's the thing. I created a fresh vue application using the vue-cli (vue init webpack {projectname}). Then I installed the vue-router and finally the [vue-apollo] package with [apollo-client].
Everything seams to be working, but when I try to prerender my project using the prerender-spa-plugin I see errors inside compiled files. At first I thought that pre-renderer has problems with async operations, but it turned out that it works without problems. Only the apollo part is not working.
This is the error that I see:
TypeError: undefined is not an object (evaluating 'r._updateFromParent')
http://localhost:8000/static/js/vendor.0c3c80024a3bb7c58eec.js:12 in st
http://localhost:8000/static/js/vendor.0c3c80024a3bb7c58eec.js:13 in y
http://localhost:8000/static/js/vendor.0c3c80024a3bb7c58eec.js:13 in v
http://localhost:8000/static/js/vendor.0c3c80024a3bb7c58eec.js:13 in y
http://localhost:8000/static/js/vendor.0c3c80024a3bb7c58eec.js:13
http://localhost:8000/static/js/vendor.0c3c80024a3bb7c58eec.js:12 in _update
http://localhost:8000/static/js/vendor.0c3c80024a3bb7c58eec.js:12
http://localhost:8000/static/js/vendor.0c3c80024a3bb7c58eec.js:13 in get
http://localhost:8000/static/js/vendor.0c3c80024a3bb7c58eec.js:13 in run
http://localhost:8000/static/js/vendor.0c3c80024a3bb7c58eec.js:12 in T
http://localhost:8000/static/js/vendor.0c3c80024a3bb7c58eec.js:13 in t
Here is also a repository with my code. Just run npm run build, then check the ./dist/index.html file.
Also published here: https://github.com/Akryum/vue-apollo/issues/8
If everything else is working though, it sounds like it has to either be phantomjs or vue-apollo. It's possible that vue-apollo is using a browser feature that isn't yet supported in phantomjs.
I think it could be related to this issue.
The example below works:
var page = require('webpage').create();
page.settings.loadImages = false
page.settings.localToRemoteUrlAccessEnabled = true
page.settings.resourceTimeout = 15000
page.onInitialized = function() {
if(page.injectJs('core.js')) { // FIX PROBLEMS
console.log("Polyfills loaded");
}
};
page.open('http://localhost:8080');
setTimeout(function () {
var html = page.evaluate(function () {
return document.documentElement.outerHTML
});
console.log(html.trim())
phantom.exit()
}, 3000)
The problem definitely represents the Phantom.js. I would propose the http://www.nightmarejs.org/ package instead (it uses a modern browser through electron).
I remember researching nightmare previously and having to rule it out for this kind of work, but that was possibly ~6 months ago, so it's possible whatever the problem was, it's fixed now.
I might not have time to explore that in the very near future, but if you wanted to fork this project and try to port it to nightmare, I'd be very curious. I'm definitely not opposed to adding nightmare as an alternative rendering option.
I'm also open to a PR that injects core.js.
I'm glad to hear that. I think that Nightmere is a good replacement and it works (tested). Let's leave this issue opened and I'll try to jump in, but I'm not sure when.
@xpepermint I tried working on the same code you have written. But the console is not displaying the polyfills loaded. Maybe there is an error in this part page.onInitialized = function() { if(page.injectJs('core.js')) { // FIX PROBLEMS console.log("Polyfills loaded"); } };
Do we need to install babel-polyfill or core.js before that?
@satyadeeproat at the end I decided to write a simple SSR package vue-builder.
Fixed in the 2.0 release, as we now inject core.js into phantom before prerendering. 🎉