question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proper way to implement modules || window not defined error

See original GitHub issue

I’m trying to implement a vue3-scroll-spy plugin on vitesse.

On dev mode runs perfectly, but when i make a build, throws a window is not defined error.

[vite-ssg] Build for server...
vite v2.5.1 building SSR bundle for production...
✓ 57 modules transformed.
.vite-ssg-temp/manifest.webmanifest        0.38 KiB
.vite-ssg-temp/main.js                     80.82 KiB
.vite-ssg-temp/assets/style.7b14a73e.css   21.66 KiB
ReferenceError: window is not defined
    at C:\Users\Icaeth\Desktop\Workspace\vitesse2\node_modules\.pnpm\vue3-scroll-spy@1.0.8\node_modules\vue3-scroll-spy\dist\index.js:1:11364
    at C:\Users\Icaeth\Desktop\Workspace\vitesse2\node_modules\.pnpm\vue3-scroll-spy@1.0.8\node_modules\vue3-scroll-spy\dist\index.js:1:14963
    at C:\Users\Icaeth\Desktop\Workspace\vitesse2\node_modules\.pnpm\vue3-scroll-spy@1.0.8\node_modules\vue3-scroll-spy\dist\index.js:1:143
    at Object.<anonymous> (C:\Users\Icaeth\Desktop\Workspace\vitesse2\node_modules\.pnpm\vue3-scroll-spy@1.0.8\node_modules\vue3-scroll-spy\dist\index.js:1:261)
    at Module.o._compile (C:\Users\Icaeth\Desktop\Workspace\vitesse2\node_modules\.pnpm\jiti@1.11.0\node_modules\jiti\dist\v8cache.js:2:2778)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at n (C:\Users\Icaeth\Desktop\Workspace\vitesse2\node_modules\.pnpm\jiti@1.11.0\node_modules\jiti\dist\v8cache.js:2:2472)
 ERROR  Command failed with exit code 1.

i can use client-only and works perfectly, but how can avoid this error or integrate modules only in client mode.    I try this in vue3-scroll-spy.ts

import { registerScrollSpy } from 'vue3-scroll-spy'
import { UserModule } from '~/types'

// Scroll spy Integration
export const install: UserModule = ({ isClient, app }) => {
  if (isClient)
    registerScrollSpy(app)
}

This is the module repo: https://github.com/bennyxguo/vue3-scroll-spy#readme

on nuxt I write ssr:false and works fine, how is the proper way in vitesse?

Thanx in advance

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
userquincommented, Aug 25, 2021

try removing/comment out the mock option from ssgOptions on vite.config.ts file

0reactions
userquincommented, Aug 25, 2021

@icaeth next time use discord server on Vite Land to ask questions, this is for issues related to the repo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to solve "window is not defined" errors in React and Next.js
First solution: typeof​​ Rogier Nitschelm for reminding me about this. I initially tried to do if (typeof window !== undefined) and this failed ......
Read more >
How To Solve ReferenceError window is not defined in ...
Fixing a window is not defined error can be quite simple. In most cases, all you will need to do is wrap your...
Read more >
Gatsby - the window is not defined error, what and how to fix it?
You can check if the browser-global object window is defined and based on it, execute the related code block. Copy. const isBrowser =...
Read more >
window is not defined · Issue #6080 · vercel/next.js - GitHub
Steps to produce the error after install react modules: Open cmd as administration; run "yarn run dev"; localhost:3000 started; open chrome ...
Read more >
ReferenceError: window is not defined in React - Stack Overflow
If your running this in node, yes there is no window object in node.js.. I assume SpeakTTS is a Browser component, so it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found