Skip to content
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

Your app is relying on a Realm global, which will be removed in realm-js v13, please update your code to ensure you import Realm #6209

Closed
hpelitebook745G2 opened this issue Oct 22, 2023 · 3 comments
Labels

Comments

@hpelitebook745G2
Copy link

hpelitebook745G2 commented Oct 22, 2023

How frequently does the bug occur?

Always

Description

I wanted to implement a Singleton class for Realm to ensure reusability throughout the application. Creating a separate instance for each component doesn't seem practical.

Stacktrace & log output

WARN  Your app is relying on a Realm global, which will be removed in realm-js v13, please update your code to ensure you import Realm:

 import Realm from "realm"; // For ES Modules
 const Realm = require("realm"); // For CommonJS

 To determine where, put this in the top of your index file:
 import Realm from "realm";
 Realm.flags.THROW_ON_GLOBAL_REALM = true

Can you reproduce the bug?

Always

Reproduction Steps

  1. Create a file that holds Realm instance
const realm = new Realm({ schema: [TestSchema] })

export default realm
  1. Import this from your component
  2. Get the warning

Versions:

"@realm/react": "^0.6.1",
"realm": "^12.2.1",
"realm-flipper-plugin-device": "^1.1.0",

Version

12.2.1

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

iOS 17 and Android 11.0

Build environment

Which debugger for React Native: Flipper Version 0.228.0 (50.0.0)

Cocoapods version

1.13.0

@kraenhansen
Copy link
Member

kraenhansen commented Oct 23, 2023

Please try setting the THROW_ON_GLOBAL_REALM as outlined here, to figure out where you're using Realm without an import:

import { flags } from "realm";
flags.THROW_ON_GLOBAL_REALM = true;

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Oct 23, 2023
@buster95
Copy link

this is because you are using Realm without import check your Schemas and every part you use Realm.

for example you can define a schema in this way

export class PersonSchema extends Realm.Object<Person> {
  name!: string
  age?: number

  static schema: Realm.ObjectSchema = {
    name: 'Person',
    properties: {
      name: 'string',
      age: 'int?',
    },
  }
}

but the right way is this

import Realm from 'realm' // <-- check yours imports

export class PersonSchema extends Realm.Object<Person> {
  name!: string
  age?: number

  static schema: Realm.ObjectSchema = {
    name: 'Person',
    properties: {
      name: 'string',
      age: 'int?',
    },
  }
}

@congduong97
Copy link

Screenshot 2023-12-01 at 12 10 08 Thanks @buster95 , it worked. my problem when create new item use Realm.BSON for id without import Realm

@nirinchev nirinchev closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2024
@sync-by-unito sync-by-unito bot closed this as completed Mar 20, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants