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.

ReferenceError: window is not defined

See original GitHub issue

Describe the bug After some time (from 1.0.0-next.87) I am using SvelteKit again.

With 87 I can use console.log(window.localStorage) in $layout.svelte.

If I use the same code now (with 108) it throws with:

ReferenceError: window is not defined
  at __layout.svelte:5:43

NOTE: the default SvelteKit init demo comes without adapters, should I add one? Is this the issue?

To Reproduce

  • npm init svelte@next my-app
  • cd my-app
  • npm install
  • add console.log(window.localStorage) to __layout.svelte right before </script>
  • npm run dev

Expected behavior It prints in console.

Information about your SvelteKit Installation:

Diagnostics
  • The output of npx envinfo --system --npmPackages svelte,@sveltejs/kit,vite --binaries --browsers:

    System: OS: Windows 10 10.0.19042 Binaries: Node: 14.17.0 - C:\Program Files\nodejs\node.EXE npm: 7.13.0 - C:\Program Files\nodejs\npm.CMD npmPackages: @sveltejs/kit: 1.0.0-next.108 => 1.0.0-next.108 svelte: 3.38.2 => 3.38.2 vite: 2.3.3 => 2.3.3

  • Your browser: Chrome 90

  • Your adapter: none

Severity I cannot work.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
rdelacommented, Jun 20, 2022

Re: gustavneustadt comment above for people finding this issue in the future

comment on https://github.com/sveltejs/kit/issues/4849 by mrkishi:

If you have fallback: ‘index.html’ configured, that will clash with your actual routes/index.svelte route since they’d both be rendered into index.html. You should name your fallback differently and configure your server/platform to serve it for all requests that don’t have a matching html file.

see also:

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
How to solve "window is not defined" errors in React and Next.js · 1. First solution: typeof · 2. Second solution: the useEffect...
Read more >
referenceerror: window is not defined, how to solve
Here's how to fix the “referenceerror: window is not defined” error that you might have in Node.js or with a tool like Next.js....
Read more >
[Solved] ReferenceError : window is not defined - ItsJavaScript
The ReferenceError : window is not defined error mainly occurs if you are using the window object in Node.js, React.js, Next.js.
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 >
ReferenceError : window is not defined at object. <anonymous ...
window is a browser thing that doesn't exist on Node.js, but ES2020 introduced globalThis , which (being part of the JavaScript ...
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