-
Notifications
You must be signed in to change notification settings - Fork 96
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 #10
Comments
could you please give some context on it? |
when i am running in node environment getting this error ReferenceError: navigator is not defined. |
This library is designed for in-browser usage in the first place. What are you trying to achieve using it in node env? |
yes, i am using this in angular js but still same issue |
The reason it throws an error is that there is no How does it fail while using angular? |
@RusinovAnton you can use the library using a script tag the problem happens because DeviceUUID function is IIFE so it will be invoked directly when you importe it the final code after adding the script tag should be like this const $window = (() => { you can mock the window to avoid it |
@RusinovAnton
im using a mock browser , in server.ts file :
@ezzabuzaid thanks |
It's been a while and I don't exactly remember what I've done to make it work, my bad didn't provide much information back then and I am no longer working on that project. I would advise to lazy load the script and run it only in browser env constructor( @Inject(PLATFORM_ID) platformId) {
const isBrowser = isPlatformBrowser(platformId);
// Lazy load "device-uuid"
} |
@ezzabuzaid but i checked isPlatformBrowser anywhere project use 'deviceuuid' |
@mkhalesi the issue is when you import the library, the navigator will be immediately be used regardless of where you use |
@ezzabuzaid
and worked properly |
@ezzabuzaid can you please guide me to run the same in react js ssr? |
@sankar2389 Same steps, check if you're in a browser environment, if so then lazy load the library. I don't have much knowledge in react - you can run the import function in |
Solved by calling the library in useEffect. |
For next.js, (react) useEffect(()=>{ },[]) |
resolved this with async await in nextjs/react app const generateDeviceId = async () => {
}; |
No description provided.
The text was updated successfully, but these errors were encountered: