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

Reference to "global" in code intended to run in the browser #95

Open
notclive opened this issue Sep 23, 2022 · 3 comments
Open

Reference to "global" in code intended to run in the browser #95

notclive opened this issue Sep 23, 2022 · 3 comments

Comments

@notclive
Copy link

When I try and use the local storage hook in a vite project, running in dev mode, I get the following error:

Uncaught ReferenceError: global is not defined

Line 14 of local-storage-events.ts references global.window. As far as I'm aware global isn't a global variable in browser environments.

From this discussion I've gathered that most, but not all, bundlers transform global to window.

Could line 14 be safely rewritten to the following?

    if (typeof window.CustomEvent === 'function') {
      return;
    }
@bboydflo
Copy link

this also fails for me for the exact same reason. any tips on how to fix it? using it in a vite project.

@notclive
Copy link
Author

I've put the following

  define: {
    global: {
      window: {}
    },
  },

in vite.config.ts to workaround the problem.

@CHE1RON
Copy link

CHE1RON commented Feb 13, 2023

I've put the following

  define: {
    global: {
      window: {}
    },
  },

in vite.config.ts to workaround the problem.

Sadly, this doesn't fix it for me - it'd be great to see support of Vite in @rehooks/local-storage though as it's been around for quite some time & becoming really popular too 😉

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