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

ReferenceError: Cannot access uninitialized variable on Safari #2889

Closed
pheuter opened this issue Nov 24, 2021 · 14 comments
Closed

ReferenceError: Cannot access uninitialized variable on Safari #2889

pheuter opened this issue Nov 24, 2021 · 14 comments

Comments

@pheuter
Copy link

pheuter commented Nov 24, 2021

Describe the bug

Running Svelte Kit app using > svelte-kit dev --port 3001 works in Chrome but throws the following error only in Safari:

ReferenceError: Cannot access uninitialized variable.

Issue is in async _load_node({ status, error, module, page, stuff }) {} in .svelte-kit/dev/runtime/internal/start.js

image

For some reason, Safari doesn't like the fact that the variable is named module and further thinks it's undefined?

Reproduction

Any svelte-kit boilerplate.

Logs

No response

System Info

System:
    OS: macOS 12.0.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 4.38 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.1.0 - ~/.nvm/versions/node/v17.1.0/bin/node
    npm: 8.1.2 - ~/.nvm/versions/node/v17.1.0/bin/npm
  Browsers:
    Chrome: 96.0.4664.55
    Safari: 15.1
  npmPackages:
    @sveltejs/adapter-node: 1.0.0-next.55 => 1.0.0-next.55 
    @sveltejs/kit: 1.0.0-next.199 => 1.0.0-next.199 
    svelte: 3.44.2 => 3.44.2 

Severity

blocking all usage of SvelteKit

Additional Information

Screen Shot 2021-11-24 at 10 26 48 AM

@Rich-Harris
Copy link
Member

I can't reproduce this in Safari 15.1. Is it still occurring?

@pheuter
Copy link
Author

pheuter commented Apr 24, 2022

@Rich-Harris Thanks for checking in, I haven't been able to reproduce it anytime recently, likely due to some third-party library that interfered with SSR.

@Rich-Harris
Copy link
Member

cool — will close this, feel free to open a new issue with repro if you encounter it again. thanks

@brittianwarner
Copy link

brittianwarner commented Dec 6, 2022

@Rich-Harris This is occurring for me in Safari when trying to access dynamic routes. Let me know if you need more information about my project.

Edit: Safari Version 15.6

image

image

@segovo
Copy link

segovo commented Jan 13, 2023

+1 I'm also having this issue (Safari 16.1), it only happens while running in dev and not in any builds.

No issues on chrome, no idea what's causing it yet.

@geoffrich
Copy link
Member

@segovo @brittianwarner if you are still experiencing this issue, please open a new issue with a reproduction

@pheuter
Copy link
Author

pheuter commented Jan 14, 2023

@geoffrich No problem, #8529

@brittianwarner
Copy link

brittianwarner commented Apr 9, 2023

@Rich-Harris @pheuter We finally resolved this issue by removing the esnext build target in our vite config, which was there for a couple of top-level awaits. This bug in webkit is what ultimately made us try this update. Hoping this helps someone that is currently telling everyone, "Safari is the new IE" :).

@TuffDev

@Smilefounder
Copy link

@brittianwarner could you help to explain more on the action? Please.
"We finally resolved this issue by removing the esnext build target in our vite config"

@braden-w
Copy link

braden-w commented Aug 19, 2023

Just in case anybody else is stumbling upon this issue—opening the Tauri app in Chrome under port 5173 (or whatever port you have configured) enabled me to solve the issue. It turns out that I had variables that were accessed before declaration, and the details in Chrome were far more detailed (for some reason Safari gives cryptic errors).

When you open this in Chrome, you should see

ReferenceError: <variableName> is not defined

and you can address it appropriately. Had this issue many times and this has always been the fix. It seems like others in this issue are facing other issues, however.

@thesiti92
Copy link

thesiti92 commented Dec 16, 2023

we just started experiencing this bug when upgrading to SvelteKit 2. worked fine before, now its breaking only in safari (16.5 for me) on line 12 in exports.js:

function validate(module, file) {
		if (!module) return;

		for (const key in module) {
			if (key[0] === '_' || expected.has(key)) continue; // key is valid in this module

			const values = [.

im trying to repro in a standalone environment, but currently having trouble. Either way we cannot upgrade to v2 right now as it breaks all Safari usage. Would appreciate any help you guys may have!

@brittianwarner
Copy link

@thesiti92 Are you using any top level awaits? I don't think v2 supports top level awaits but this was my issue a while ago. Try spinning up a clean v2 project and see if it is still happening and you can at least narrow it down to something unique about your project. I worked through this a while ago and the best thing to do is try to follow best practices.

@thesiti92
Copy link

I opened a new ticket, seems to be something with the sveltekit 2 runtime #11364

@jamestinman
Copy link

Also having this issue with Safari
image

Debugging the old-school way by cutting out code, it is triggered (for me) by inclusion of public env

  import { env } from '$env/dynamic/public';

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

No branches or pull requests

9 participants