Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get ReferenceError: window is not defined, when updating kit from 1.7.2 to ^1.8.0 #9518

Closed
akralj opened this issue Mar 26, 2023 · 4 comments

Comments

@akralj
Copy link

akralj commented Mar 26, 2023

Describe the bug

I have a medium complex SPA with works offline through workbox and pouchdb.
When updating from kit 1.7.2 to any version higher than 1.8.0 I get this errror in my terminal and a 500 Internal error in the browser:

[client] ReferenceError: window is not defined
[client]     at Module.render_response (/node_modules/@sveltejs/kit/src/runtime/server/page/render.js:257:3)
[client]     at Module.render_page (/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:126:16)
[client]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[client]     at async resolve (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:363:17)
[client]     at async Module.respond (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:234:20)
[client]     at async file:///home/a/dev/ubii/client/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:501:22

It is impossible for me to make an minimal example, because of the complexity of the code. So if anybody could give me an idea what changed between 1.7.2 and 1.8.0 which could possible cause this error, I would be very grateful.
I have the usual SPA configs in place and everything works from version 1.0.0 on without problem, so i really don't know where to start debugging.
Thanks a lot for your time

Reproduction

Not possible, because of the complexity of the app.

Logs

No response

System Info

System:
    OS: Linux 5.19 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
    CPU: (12) x64 AMD Ryzen 5 4600H with Radeon Graphics
    Memory: 6.25 GB / 15.00 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.15.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.5.0 - /usr/bin/npm
  Browsers:
    Chromium: 111.0.5563.64
    Firefox: 110.0.1
  npmPackages:
    @sveltejs/adapter-static: 2.0.1 => 2.0.1 
    @sveltejs/kit: ^1.8.0 => 1.8.0 
    svelte: ^3.44.0 => 3.57.0 
    vite: ^4.0.0 => 4.2.1

Severity

blocking an upgrade

Additional Information

No response

@eltigerchino
Copy link
Member

eltigerchino commented Mar 26, 2023

Possibly related to #9487

EDIT: my bad. They're not related

@akralj
Copy link
Author

akralj commented Mar 26, 2023

Possibly related to #9487

My app works with vite@4.1.4 or vite@4.2.1 all the same. so I don't think it is related to #9487. In my case, just updating kit from 1.7.2 to 1.8.0 throws the above error. all other deps are at their latest version.

@Conduitry
Copy link
Member

If it's not possible for you to provide a minimal reproduction, it's not possible for anyone to help you.

@akralj
Copy link
Author

akralj commented Mar 27, 2023

It was vite related after all. funny that this changed from kit@1.7.2 to kit@1.8.0
Had to replace global: "window" in vite.config.js:

const config = {
	build: {
		target: 'es2022'
	},
	define: {
		global: "window",
	},
    }
	},
	plugins: [sveltekit()],
}

with esbuildOptions:

const config = {
	build: {
		target: 'es2022'
	},
	optimizeDeps: {
          esbuildOptions: {
           define: {
            global: 'globalThis'
          }
      }
	},
	plugins: [sveltekit()],
}

to make pouchdb and other libs which depend on "window" work.
hopefully this can help someone else.
peace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants