Could not Initialize the Realm App Client

Hi Everyone, I am learning to use Mongodb Realm. I am trying to connect Realm App Client in my web sdk. But getting Realm.App.getApp is not a function error. Please see my code below and help me where I am doing wrong here.
In HTML,
<script src="https://unpkg.com/realm-web@0.8.0/dist/bundle.iife.js"></script>

In JS,

const id = ‘< My App ID>’; // replace this with your App ID

const config = {
id,
};
const app = new Realm.App(config);

async function loginAnonymous() {

// Create an anonymous credential
const credentials = Realm.Credentials.anonymous();
try {
  // Authenticate the user
  const user = await app.logIn(credentials);
  console.log(app.currentUser);
  // `App.currentUser` updates to match the logged in user
  return user
} catch(err) {
  console.error("Failed to log in", err);
}

}
loginAnonymous().then(user => {
console.log(“Successfully logged in!”, user)
const app = Realm.App.getApp(“< My App ID>”); // replace this with your App ID
// Getting error here as Realm.App.getApp is not a function
})

It looks like you’re using an older version, can you try using realm-web@1.2.0 in the HTML instead of 0.8.0?

1 Like