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

Getting error when checking if window is defined #316

Open
droplab opened this issue Aug 24, 2020 · 4 comments
Open

Getting error when checking if window is defined #316

droplab opened this issue Aug 24, 2020 · 4 comments

Comments

@droplab
Copy link

droplab commented Aug 24, 2020

I would think checks for window itself would've been wrapped with a try/catch so this would work out of the box?

is.existy(window) or is.windowObject(window)

Getting error - ReferenceError: window is not defined

@evdama
Copy link

evdama commented Mar 20, 2022

this is probably happening because the test is not run in an environment where window exists e.g. on node

@evdama
Copy link

evdama commented Mar 20, 2022

I've been upgrading/migrating the entire lib over the last few days so feel free to send a PR https://github.com/evdama/is-it-check

@evdama
Copy link

evdama commented Mar 21, 2022

I've added a litte information on this matter, added test, plus, the errors don't occur anymore evdama@31ad329

Close this issue if you're happy with the result

@evdama
Copy link

evdama commented Mar 21, 2022

If you'd be using this in some SSR or Node.js environment I'd recommend a try/catch block in your own code

try {
  console.log('is.existy(window): ', is.existy(window))     // will throw an error if not run in a web browser
} catch (error) {
  console.log('no window object on Node.js: ', error)
}

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

2 participants