locomotivemtl / locomotive-scroll

🛤 Detection of elements in viewport & smooth scrolling with parallax.
https://locomotivemtl.github.io/locomotive-scroll
MIT License
7.97k stars 1.12k forks source link

Nuxt 3 - window is not defined #502

Open mak33v opened 1 year ago

mak33v commented 1 year ago

Hello 👋

Nuxt 3 5.2 - window is not defined

RayJason commented 1 year ago

You should init it in

onMounted(() => nextTick(()=>{..}))
soulinmaikadua commented 1 year ago

same issue Nuxt 3.7.3 window is not defined after install install vue3-apexcharts and apexcharts

kieranmansfield commented 1 year ago

Same issue, nuxt 3.8.0.

Tried this, didn't solve it for me. @RayJason

You should init it in

onMounted(() => nextTick(()=>{..}))

Error message -

500
window is not defined
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

and terminal is showing me this -

[Vue warn]: Component LayoutLoader is missing template or render function.
evilmastermind commented 1 year ago

Same issue for me in nuxt 3.8.0. It's from a component that's used in a route that is supposed to be set to { ssr: false }... so window should be available in it?

500
window is not defined

at setup ([my project folder]\components\Navbar\Theme.js:41:5)
at _sfc_main.setup ([my project folder]\components\Navbar\Theme.js:95:23)
at callWithErrorHandling ([my project folder]\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:156:18)
at setupStatefulComponent ([my project folder]\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:7244:25)
at setupComponent ([my project folder]\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:7205:36)
at renderComponentVNode ([my project folder]\node_modules\@vue\server-renderer\dist\server-renderer.cjs.js:614:15)
at Module.ssrRenderComponent ([my project folder]\node_modules\@vue\server-renderer\dist\server-renderer.cjs.js:86:10)
at [my project folder]\components\Navbar\Settings.js:113:38
at renderFnWithContext ([my project folder]\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:767:13)
jibrilmohamod commented 1 year ago

Anyone have a solution , I'm getting the same error.

cmarcelly commented 8 months ago

Try to use this plugin to import the library: https://github.com/bluwy/vite-plugin-iso-import

pieterjanmaes commented 5 months ago

This works for me:

// ./plugins/locomotive.client.ts

import LocomotiveScroll from 'locomotive-scroll';

export default defineNuxtPlugin(nuxtApp => {
  let locomotiveScroll: LocomotiveScroll | null = null;

  nuxtApp.hook('page:start', () => {
    locomotiveScroll?.destroy();
  });

  nuxtApp.hook('page:finish', () => {
    locomotiveScroll = new LocomotiveScroll();
  });
});

I'm using: