I'm building out a react native app with typescript and wanted to test out realm.
i create my getRealm.ts file with the following code:
import Realm from "realm";
let app;
// Returns the shared instance of the Realm app.
export function getRealmApp() {
if (app === undefined) {
const appId = process.env.MONGO_REALM_API!; // Set Realm app ID here.
const appConfig = {
id: appId,
timeout: 10000,
app: {
name: "default",
version: "0",
},
};
app = new Realm.App(appConfig);
}
return app;
}
and followed with the file where i hoped to use it in:
import React, { useState } from "react";
import { Button, View } from "react-native";
import { Provider } from "react-redux";
import Textbox from "./components/textbox";
import { getRealmApp } from "./realm/getRealmApp";
import { store } from "./redux";
import Realm from "realm";
const app = getRealmApp();
const MainEntry = () => {
const [email, setEmail] = useState("[email protected]");
const [password, setPassword] = useState("testing123");
const longinHandler = async () => {
const creds = Realm.Credentials.emailPassword(email, password);
const newUser = await app.logIn(creds);
console.log(newUser);
};
return (
<Provider store={store}>
<View>
<Textbox placeholder="Email" />
<Textbox placeholder="password" />
</View>
<Button title={"Login"} onPress={longinHandler} />
</Provider>
);
};
export default MainEntry;
I saved the file and wanted to test the login function just see what type of data is being sent back. The moment i saved the file, the application couldn't run and returned :
WARN Require cycle: index.js -> App.tsx -> src/index.tsx -> src/realm/getRealmApp.ts -> index.js
Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
[Sun Jan 24 2021 16:27:44.683] WARN Require cycle: index.js -> App.tsx -> src/index.tsx -> index.js
Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
[Sun Jan 24 2021 16:27:44.684] ERROR TypeError: undefined is not a constructor (evaluating 'new _realm.default.App(appConfig)')
[Sun Jan 24 2021 16:27:44.684] ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
[Sun Jan 24 2021 16:27:44.685] ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
Please help
question from:
https://stackoverflow.com/questions/65871802/getting-type-error-is-not-a-constructor-in-realm-with-react-native-typescript 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…