Description
¿Will SSR be supported?
ReferenceError: window is not defined
at C:\app\node_modules\vue-infinite-loading\dist\vue-infinite-loading.js:1:12046
at C:\app\node_modules\vue-infinite-loading\dist\vue-infinite-loading.js:1:11978
at p.exports (C:\app\node_modules\vue-infinite-loading\dist\vue-infinite-loading.js:1:12264)
at Object. (C:\app\node_modules\vue-infinite-loading\dist\vue-infinite-loading.js:1:12740)
at e (C:\app\node_modules\vue-infinite-loading\dist\vue-infinite-loading.js:1:408)
at Object.module.exports.render._h.staticClass (C:\app\node_modules\vue-infinite-loading\dist\vue-infinite-loading.js:1:9170)
at e (C:\app\node_modules\vue-infinite-loading\dist\vue-infinite-loading.js:1:408)
at Object. (C:\app\node_modules\vue-infinite-loading\dist\vue-infinite-loading.js:1:640)
at e (C:\app\node_modules\vue-infinite-loading\dist\vue-infinite-loading.js:1:408)
at p.__esModule.default (C:\app\node_modules\vue-infinite-loading\dist\vue-infinite-loading.js:1:496)
Activity
PeachScript commentedon Oct 9, 2016
Excuse me, I don't know what is the
SSR
, could you explain to me?cwirz commentedon Oct 10, 2016
here: https://rc.vuejs.org/guide/ssr.html
cwirz commentedon Oct 10, 2016
Does someone know how to prevent this error?: ReferenceError: window is not defined
PeachScript commentedon Oct 10, 2016
Thanks for your explanation @Wirzi ,
SSR
stands forServer-Side rendering
.But in fact I hasn't been used it, so I need some time to try it, if you solved this problem, please help me to improve this plugin, thanks again :)
cwirz commentedon Oct 10, 2016
Sure I will help but i just started to use
server side rendering
.I think we should change the code to make sure
window
is not called when code is running on server, because there is no window in node: https://rc.vuejs.org/guide/ssr.html#Simple-SSR-with-the-Express-Web-Serverjosemanuelp commentedon Jan 5, 2017
I could make it work using jsdom.
put this at the top of server/express source file.
Note: Still better that the plugin check for the existence of window var.
diogobeda commentedon Jan 18, 2017
I had to use this project on a server rendered app and made some changes to make it work. I currently don't have too much time to make an appropriate pull request, but I'll leave the commit that made it work here if anyone or the author wants to turn it into an actual pull request for both
master
andnext
branches.This is the commit:
https://github.com/diogobeda/vue-infinite-loading/commit/ce4fa5594bcd1d11a13c1abe9cd2012e7b3014ed
What I had to do was:
style-loader
was referencingwindow
import Vue from 'vue'
to register it globally.cc @PeachScript
PeachScript commentedon Jan 19, 2017
@diogobeda Thank you very much! I try your solution and find the key point to support SSR, the key point is the
style-loader
doesn't support local export, details in here, so I think we cannot find a prefect solution before thestyle-loader
changes.And I found a workaround to support SSR, you just need two steps for your SSR app:
import InfiniteLoading from 'vue-infinite-loading/src/components/Infiniteloading.vue';
instead ofimport InfiniteLoading from 'vue-infinite-loading;
npm install less less-loader --save-dev
if you have not installed themI tested it successfully with this demo vue2-ssr-example, perhaps this workaround can help you :D @tobeorla @cwirz @josemanuelp @diogobeda
diogobeda commentedon Jan 19, 2017
Awesome @PeachScript. I was using my forked version, will definitely use your workaround now. Thanks :)
PeachScript commentedon Jan 29, 2017
Glad you like the workaround @diogobeda , I closed this issue and you can reopen it if you need in the future.
gokhanozdemir commentedon Mar 6, 2017
This solution also works with Nuxt.js, thanks @PeachScript .
PeachScript commentedon Mar 9, 2017
@gokhanozdemir you're welcome :D
mohitgupta1918 commentedon Mar 21, 2017
I am using vue-infinite-loading with nuxj.js for SSR.I did perform both the steps of workaround mentioned by @PeachScript .I am using the vue-infinite-loading in 'ListItems.vue' component
I am still getting an error:
17 remaining items
NoraGithub commentedon Jun 19, 2018
错误信息:
PeachScript commentedon Jun 19, 2018
@NoraGithub 如果是基于 Nuxt,建议配合
no-ssr
使用而不是像这样加载组件。frederic117 commentedon Oct 1, 2018
Hello
I'm using Nuxt too!
i try what @ckpiggy and @dnlup suggest but i got this error...
Please, a little help :)
fred
(function (exports, require, module, __filename, __dirname) {
^
SyntaxError: Unexpected token <
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at r (C:\Users\Frederic_2\Documents\InsidersFoot\node_modules\vue-server-renderer\build.js:8341:16)
at Object.vue-infinite-loading/src/components/InfiniteLoading.vue (server-bundle.js:105744:18)
at webpack_require (webpack/bootstrap:19:0)
at Module../node_modules/babel-loader/lib/index.js?!./node_modules/vue-loader/lib/index.js?!./client/components/connect/StreamTimelineBabble.vue?vue&type=script&lang=js& (client/components/connect/StreamTimelineBabble.vue?0e15:1:0)
at webpack_require (webpack/bootstrap:19:0)
at Module../client/components/connect/StreamTimelineBabble.vue?vue&type=script&lang=js& (client/components/connect/StreamTimelineBabble.vue?dba4:1:0)
Skasi commentedon Nov 2, 2018
@frederic117 I've had the same problem after upgrading to nuxt 2.x and node 10.x. I solved it by using a plugin that is not rendered serverside.
Add a plugin to the plugins folder:
/plugins/infinite-loading.js
Register the plugin in
nuxt.config.js
and disable SSR.Now you can use the
<infinite-loading>
component in your templates.PeachScript commentedon Nov 3, 2018
@Skasi good idea, I will add it into docs, thanks! And is the
<no-ssr></no-ssr>
also can works?Skasi commentedon Nov 6, 2018
@PeachScript when using the plugin, yes:
plugins: [ { src: '~/plugins/infinite-loading.js' } ]
in combination with<no-ssr><infinite-loading/></no-ssr>
works.But without using a plugin, when importing the component and registering it with vue I get the same error others already mentioned. It worked in the past, but no longer after updating node and nuxt.
PeachScript commentedon Nov 6, 2018
@Skasi got it, thank you for spending time on these details, it is very great and useful!
xiewl commentedon Nov 7, 2018
@PeachScript 下午好,在vue组件内直接引用import InfiniteLoading from 'vue-infinite-loading'; 再加上no-ssr标签在最新版(v2.4.0)会报找不到window。但我记得以前是可以的。然后我去翻另一个Nuxt项目的代码,发现(v2.3.1)版本是可以正常运行的。
PeachScript commentedon Nov 7, 2018
@xiewl 根据 Skasi 提供的信息,可能是新版本 Nuxt API 变动导致的,你可以参考一下他上面的评论进行验证。
xiewl commentedon Nov 7, 2018
@PeachScript 应该不是这个原因。因为我这边两个项目的nuxt都是同一个版本(v1.4.0)。不同点在于vue-infinite-loading的版本一个是(v2.4.0),一个是(v2.3.1)。我将2.4.0这个项目重装为2.3.1就正常了。我和Skasi的引用方式不太一样,我是 import InfiniteLoading from 'vue-infinite-loading'; 再加上no-ssr标签
PeachScript commentedon Nov 7, 2018
@xiewl 了解了,我这边先复现一下,感谢反馈。
PeachScript commentedon Nov 23, 2018
Hi @Skasi @xiewl , I've released a new version
v2.4.2
to fix this problem, now this plugin can works properly with Nuxt.js, just need to wrap it withno-ssr
component (like v2.3.3 and below), no need any extra configuration. Please comment here if you found any problem.kvanska commentedon Jun 4, 2019
I'm using nuxtjs 2.8 and vue-infinite-loading 2.4.4 and ran into an issue that I could not produce in a 'clean' new project. When doing a page reload, infinite-loading works as expected but when routing to a page with infinite-loading from SPA nuxt-link I got exception:
TypeError: Cannot read property 'tagName' of null at VueComponent.getScrollParent
getScrollParent recursively finds the parent element and for some reason when loading in SPA, parent node is null for:
<div class="page">
on page refresh it's not null and parent is set to window
I solved this by setting the force-use-infinite-wrapper property to the element containing the actual list and this solves the problem. I could not find out why this happens though?
connecteev commentedon Sep 15, 2019
@kvanska I've been struggling for days trying to get infinite loading to work in Nuxt with SSR. Any chance you can point to an example of this?
JanusSpark commentedon Oct 15, 2020
@Skasi Hello,I write the code like you mentioned.And It works fine in npm run dev mode. But it can't work fine with production.Do you have the same problem?And how can I init infinite-loading after the dom ready,I guess maybe it isn't init normally
<client-only><infinite-loading></infinite-loading></client-only>
I resolve it with client-only