Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-2382

BSON: For React Native please polyfill crypto.getRandomValues when using the new Realm.BSON.UUID() to generate a unique ID

      How frequently does the bug occur?

      Always

      Description

      I integrated Realm in a React Native app using version 0.71.7 , created a schema and followed the basic setup and all works perfectly fine. When I added the uuid field and used the new Realm.BSON.UUID() to generate an id, It does actually generate an Id and I confirmed it by printing the value however I receive a warning as illustrated in the image below:

      upon clicking it it expands to show:

      Stacktrace & log output

      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      WARN  BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.
      

      Can you reproduce the bug?

      Always

      Reproduction Steps

      1. create a react native project
      2. setup real by following basic real setup docs for react native
      3. add a schema that has a uuid field for ex:
      export class CarSchema extends Realm.Object<CarSchema> {
       name!: string;
      
       brand!: string;
      
       makeYear?: number;
      
       price!: number;
      
       _id!: Realm.BSON.UUID;
      
       static schema = {
         name: 'CarSchema',
         properties: {
           _id: 'uuid',
           name: 'string',
           brand: 'string',
           makeYear: 'int?',
           price: 'float',
         },
       };
      }
      
      1. in your app.tsx add the following before the return statement
       const addObject = () =>
          realm.write(() =>
            realm.create(CarSchema, {
              _id: new Realm.BSON.UUID(),
              name: 'X6',
              brand: 'BMW',
              price: 300000,
              makeYear: 2023,
            }),
          );
      

      and the following in your return statement:
      {{<Button label="add car" onPress=

      {addObject}

      />}}

      after clicking the button you will get the same warning

      Version

      latest

      What services are you using?

      Local Database only

      Are you using encryption?

      No

      Platform OS and version(s)

      android API 30

      Build environment

      Which debugger for React Native: ..

      Cocoapods version

      No response

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: