mazipan / vue-google-adsense

💰 Vue.js Google Adsense Component with InFeed and InArticle Ads support
https://mazipan.github.io/vue-google-adsense/
MIT License
257 stars 42 forks source link

ReferenceError: window is not defined #146

Closed mzhukovs closed 4 years ago

mzhukovs commented 4 years ago

Thanks for this library.

I'm trying to use it with a Gridsome project, and am getting the error below on build - not sure if it's something I can address on my end - if anyone knows a work-around please share.

ReferenceError: window is not defined at Object. (node_modules/vue-google-adsense/dist/VueGoogleAdsense.min.js:2:231) at webpack_require (webpack/bootstrap:25:0) at Module. (assets/js/app.bce76fb4.js:7608:28) at webpack_require (webpack/bootstrap:25:0) at Object. (assets/js/app.bce76fb4.js:4136:18) at __webpack_require__ (webpack/bootstrap:25:0) at assets/js/app.bce76fb4.js:118:18 at Object. (assets/js/app.bce76fb4.js:121:10) at o (C:\Repos\MY_PROJECT\node_modules\vue-server-renderer\build.prod.js:1:77607)

mazipan commented 4 years ago

Read https://github.com/gridsome/gridsome/issues/180

mzhukovs commented 4 years ago

I tried the following (and then wrapping <InArticleAdsense> in <ClientOnly> tag within the template HTML), but it doesn't appear to be working - am I missing something?

  components: {
    InArticleAdsense: () =>
      import("vue-google-adsense/dist/InArticleAdsense.min.js")
        .then((m) => m.InArticleAdsense)
        .catch(),
  },
mazipan commented 4 years ago

You can follow this commit: https://github.com/mazipan/gridsome-blog/commit/9e5600092c874a8281d642e8f0460f0e0f48ef3a @mzhukovs