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: navigator is not defined' for Next.js apps #124

Closed
nikhilxb opened this issue Sep 3, 2020 · 4 comments
Closed

'ReferenceError: navigator is not defined' for Next.js apps #124

nikhilxb opened this issue Sep 3, 2020 · 4 comments

Comments

@nikhilxb
Copy link
Contributor

nikhilxb commented Sep 3, 2020

I'm trying to use this library within my Next.js app, and I'm getting a ReferenceError: navigator is not defined thrown by this line, since navigator is not defined on the server side.

const isMac: boolean = /Mac/.test( navigator.platform );

@nikhilxb
Copy link
Contributor Author

nikhilxb commented Sep 3, 2020

I found a hack that fixes it.

Broken:

import CameraControls from 'camera-controls';
CameraControls.install({ THREE });

Working:

const CameraControls = typeof window !== `undefined` ? require("camera-controls").default : null;
if(CameraControls) CameraControls.install({ THREE });

@yomotsu
Copy link
Owner

yomotsu commented Sep 3, 2020

Ah, that's right.
We should add another condition for SSR detection in camera-controls.

I'll work on it this weekend, or you can make a PR for it if you like.

yomotsu added a commit that referenced this issue Sep 6, 2020
Detect whether node or browser
@yomotsu
Copy link
Owner

yomotsu commented Sep 6, 2020

I think this should be solved with #125

@yomotsu yomotsu closed this as completed Sep 6, 2020
@nikhilxb
Copy link
Contributor Author

Awesome, thanks!

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