-
Notifications
You must be signed in to change notification settings - Fork 19
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
XMLHttpRequest is not defined, NextJS #256
Comments
Hello @nelwincatalogo , thanks for the raising the issue. |
I'm using it in a nextjs project and my browser is up to date also |
We haven't had anyone use rLogin with NextJS so this is interesting. I was able to reproduce the error and it looks like it is coming from the NextJS compiler and not the browser. Following the advice in this StackOverflow post I added this:
This resulted in a new error that |
I was able to solve the problem by importing it only on the client side. Following nextjs dynamic imports
However, I got the following new error |
I already solved the problem, thanks a lot for the assistance cheers 🍻 Here's how I resolved the problem: // rLoginProvider.js
const rLogin = new RLogin({
providerOptions: {
// ...
},
});
export default rLogin;
// create a state to hold the rLogin instance
const [rLogin, setRLogin] = useState(null);
// on page load
useEffect(() => {
(async () => {
// import using ES2020 dynamic import(), nothing can stop us because Next.js supports it.
const rLoginProvider = (await import('@/app/wallet/rLoginProvider')).default;
setRLogin(rLoginProvider);
// ...
})();
}, []);
// then you can use it now however you like
const _rLogin = await rLogin.connect();
const web3 = new Web3(_rLogin.provider); |
I wonder why |
Great, I'm glad you got it to work! I don't know a lot about NextJS so sorry I wasn't able to assist more. If I get some time, I might borrow your implementation to use in our sample apps to show others how to use rLogin with NextJS. Regarding the other wallets, a browser can only have one wallet 'enabled' at a time since they all attempt to overwrite the |
What went wrong?
What have you tried so far to fix?
I did try to installing xmlhttprequest but no luck.
The text was updated successfully, but these errors were encountered: