Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting "document is not defined" after upgrading to 0.5.6 #82

Closed
goldfire opened this issue Apr 6, 2017 · 21 comments
Closed

Getting "document is not defined" after upgrading to 0.5.6 #82

goldfire opened this issue Apr 6, 2017 · 21 comments

Comments

@goldfire
Copy link

goldfire commented Apr 6, 2017

We've been using vue-meta with SSR on 0.5.5, but after upgrading to 0.5.6 we started getting the following errors on the server:

ReferenceError: document is not defined
    at updateClientMetaInfo (/path/to/node_modules/vue-meta/lib/vue-meta.js:824:19)
    at Vue$2.refresh (/path/to/node_modules/vue-meta/lib/vue-meta.js:885:35)
    at /path/to/node_modules/vue-meta/lib/vue-meta.js:1013:74
    at Timeout._onTimeout (/path/to/node_modules/vue-meta/lib/vue-meta.js:924:5)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)
@ziazon
Copy link

ziazon commented Apr 7, 2017

Same here. Here's my error using 0.5.6 (which I don't get using 0.5.5)

/path/to/project/node_modules/vue-meta/lib/vue-meta.js:824
    var htmlTag = document.getElementsByTagName('html')[0];
                  ^

ReferenceError: document is not defined
    at updateClientMetaInfo (/path/to/project/node_modules/vue-meta/lib/vue-meta.js:824:19)
    at Vue$2.refresh (/path/to/project/node_modules/vue-meta/lib/vue-meta.js:885:35)
    at /path/to/project/node_modules/vue-meta/lib/vue-meta.js:1013:74
    at Timeout._onTimeout (/path/to/project/node_modules/vue-meta/lib/vue-meta.js:924:5)
    at ontimeout (timers.js:380:14)
    at tryOnTimeout (timers.js:244:5)
    at Timer.listOnTimeout (timers.js:214:5)

For now I've reverted back to 0.5.5 but it would be nice to upgrade soon :)

@kasparasg
Copy link

^^ having the same issue with an upgrade to 0.5.6

@rhwilr
Copy link
Contributor

rhwilr commented Apr 13, 2017

Are you guys also using vuex-router-sync?
I am using nuxt.js with vuex-router-sync installed as a plugin and i just found out that if I only include router-sync in the browser-build I don't get the crash.

@darrynten
Copy link

darrynten commented Apr 13, 2017

@rhwilr exact same problem with vuex-router-sync and 0.5.6 for me - going back to0.5.5 fixes it for me - I'm hesitant to only include it on the client

@goldfire
Copy link
Author

Yes, we are using vuex-router-sync as well.

@harvey-woo
Copy link

Having the same issue, too, with vuex-router-sync

@euaaaio
Copy link

euaaaio commented Apr 19, 2017

Maybe i'm wrong, but i have the same problem both in the 0.5.5 and 0.5.6

@rhwilr
Copy link
Contributor

rhwilr commented Apr 19, 2017

I submitted a PR last week which fixes the issue for me. #84
Maybe some of you could check it out and give feedback if it works for you as well so we can get this merged in.

@MaximilianLloyd
Copy link

Got the same error, had to downgrade. Kinda strange that a breaking change hasn't been addressed by the repo owner in two weeks :-/.

@cannap
Copy link

cannap commented Apr 21, 2017

@MaximilianLloyd maybe busy or holidays 💃

@jazoom
Copy link
Contributor

jazoom commented Apr 23, 2017

@rhwilr The interesting thing is that when I made that pull request, it worked fine. I didn't think destroyed() would even be called on the server. I'm not sure why this issue didn't pop up before, because it definitely is now.

Sorry everyone for causing the havoc.

@euaaaio
Copy link

euaaaio commented Apr 23, 2017

@rhwilr , hmm, it works for me(0.5.6), thanks

@shelakel
Copy link

This issue is still present, and I've confirmed the fix from @rhwilr solves the issue:
add

// do not trigger refresh on the server side
if (this.$isServer) return

before batchUpdate in destroyed

@corsen2000
Copy link

I am not using vue-router-sync, but I am making use of store.registerModule, and it looks like that code is causing the problem. If I do not use registerModule and instead define that module with the initial store everything is fine.

I notice vue-router-sync also makes use of registerModule, so perhaps this issue has something to do with dynamic module registration.

@Atinux
Copy link
Member

Atinux commented May 15, 2017

Should be fixed with vue-meta@1.0.0

@Atinux Atinux closed this as completed May 15, 2017
@nilsi
Copy link
Contributor

nilsi commented May 15, 2017

Im still seeing this problem with vue-meta@1.0.0 and above. Using SSR.

W20170515-23:39:52.781(9)? (STDERR)/path/to/project/vue-meteor-demo/node_modules/vue-meta/lib/vue-meta.js:835
W20170515-23:39:52.781(9)? (STDERR)     var htmlTag = document.getElementsByTagName('html')[0];
W20170515-23:39:52.782(9)? (STDERR)                   ^
W20170515-23:39:52.782(9)? (STDERR) 
W20170515-23:39:52.782(9)? (STDERR) ReferenceError: document is not defined
W20170515-23:39:52.783(9)? (STDERR)     at updateClientMetaInfo (/path/to/project/vue-meteor-demo/node_modules/vue-meta/lib/vue-meta.js:835:19)
W20170515-23:39:52.783(9)? (STDERR)     at Vue$3.refresh /path/to/project/vue-meteor-demo/node_modules/vue-meta/lib/vue-meta.js:896:35)
W20170515-23:39:52.784(9)? (STDERR)     at /path/to/project/vue-meteor-demo/node_modules/vue-meta/lib/vue-meta.js:1018:74
W20170515-23:39:52.784(9)? (STDERR)     at [object Object]._onTimeout (/path/to/project/vue-meteor-demo/node_modules/vue-meta/lib/vue-meta.js:935:5)
W20170515-23:39:52.784(9)? (STDERR)     at Timer.listOnTimeout (timers.js:92:15)

@Atinux
Copy link
Member

Atinux commented May 15, 2017

Can you create a step to reproduce this issue @nilsi ?

@nilsi
Copy link
Contributor

nilsi commented May 15, 2017

What I did was to clone this repo:
https://github.com/Akryum/vue-meteor-demo

I installed vue-meta with:

npm install vue-meta --save

And added imported Meta in app.js:

import Meta from 'vue-meta'
Vue.use(Meta)

Then when I try to access the page Im getting this error

@jacoborus
Copy link

I'm experiencing this issue with version 1.0.4, just create a pull request with a fix that worked for me: #101

@camilodelvasto
Copy link

I'm also getting this error when running npm run generate, even with vue-meta@1.4.0. Using @jacoborus 's PR works for me locally, but that PR was closed...
Any other solution @Atinux ?

@ismail9k
Copy link

ismail9k commented Oct 16, 2020

I've managed to fix this issue in my own project. The main idea is to prevent the Vue instance from mounting on the server, by removing the el property from the Vue object on the server-side, then mount the Vue instance manually client side

/client/app.js

import Vue from 'vue';

// Meteor Tracker integration
import VueMeteorTracker from 'vue-meteor-tracker'
Vue.use(VueMeteorTracker)

import App from './ui/App.vue'
import router from './router'

function createApp () {
  return {
    app: new Vue({
      // el: '#app', <= REMOVE THIS
      router,
      ...App,
    }),
    router,
  }
}

export default createApp;

/client/startup/index.js

import { Meteor } from 'meteor/meteor'
import CreateApp from './app'

Meteor.startup(() => {
  CreateApp().app.$mount('#app');
})

You can test this on my vue-meteor-boilerplate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests