What is the solution to this code

it shows $w cannot be used before page is ready…
please what is the solution??

import wixUsers from ‘wix-users’;
import wixLocation from “wix-location”;

$w(‘#SignupRegisterButton’).onClick(() => {
wixUsers.register($w(‘#SignupEmailInput’).value, $w(‘#SignupPasswordInput’).value,{
“contactInfo”: {
“firstName”: $w(‘#SignupFirstNameInput’).value,
“lastName”: $w(‘#SignupLastNameInput’).value,
“FirstName”: $w(‘#SignupFirstNameInput’).value,
“LastName”: $w(‘#SignupLastNameInput’).value,
“Account Name”: $w(‘#SignUpAccountNameInput’).value,
“Account Number”: $w(‘#SignUpAccountNumberInput’).value,
“password”: $w(‘#SignupPasswordInput’).value,
“Phone Number”: $w(‘#SignUpPhoneNumberInput’).value,
“Packages”: $w(‘#SignUpPackagesDropdown’).value
}
}).then(() => {
//Everything went good, user was registered, now going to redirect
console.log(‘user registered successfully’);
wixLocation.to(‘/Merge’);
}). catch ((err) => {
//If there is an error it will not redirect, it will console.log the error
console.log(${err}: Error)
})
});

put it after onReady and thats it. Site should be ready before any code because code doesnt know what is what

yes thanks i got the solution but one more thing

  1. after user click register button it does not show the Merge page

after user click sign up it suppose to redirect to Merge page this is the code i used now

import wixUsers from ‘wix-users’;
import wixLocation from “wix-location”;

$w.onReady( function () {
$w(‘#SignupRegisterButton’).onClick((Merge) => {
wixUsers.register($w(‘#SignupEmailInput’).value, $w(‘#SignupPasswordInput’).value,{
“contactInfo”: {
“firstName”: $w(‘#SignupFirstNameInput’).value,
“lastName”: $w(‘#SignupLastNameInput’).value,
“FirstName”: $w(‘#SignupFirstNameInput’).value,
“LastName”: $w(‘#SignupLastNameInput’).value,
“Account Name”: $w(‘#SignUpAccountNameInput’).value,
“Account Number”: $w(‘#SignUpAccountNumberInput’).value,
“password”: $w(‘#SignupPasswordInput’).value,
“Phone Number”: $w(‘#SignUpPhoneNumberInput’).value,
“Packages”: $w(‘#SignUpPackagesDropdown’).value
}
}).then(() => {
//Everything went good, user was registered, now going to redirect
console.log(‘user registered successfully’);
wixLocation.to(“/Merge”);
}). catch ((err) => {
//If there is an error it will not redirect, it will console.log the error
console.log(${err}: Error)
});
});
});

i think after then you should do something like this. Its only idea but try in concole.log what result is and then

.then( (result) => {
    let status = result.status; // "Active"
    if (status = "Active") {wixlocatonto.......}}
    

showing result not defined

https://www.wix.com/code/reference/wix-users.html#register
according to this if register status should be active. Try console.log(result.status)

am having difficulty to understand this…

i tried it now still the same can not view redirected page

problem is i worked around it only not to be able to login with the email after accepting the request as a member i cannot login… please help