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

TypeError: Reflect.construct requires the first argument to be a constructor #3110

Closed
uendar opened this issue Aug 5, 2020 · 5 comments · Fixed by #3261
Closed

TypeError: Reflect.construct requires the first argument to be a constructor #3110

uendar opened this issue Aug 5, 2020 · 5 comments · Fixed by #3261
Assignees

Comments

@uendar
Copy link

uendar commented Aug 5, 2020

I am getin this error when i run : react-native run-android
First the app opens correctly and after 3 sec it shows me this error.

I have never had this before. I am using last realm version 6.0.4
Even with older versions is the same issue.

I have lot of schemas that i import in an index file :

const Realm = require('realm');

class CountriesSchema extends Realm.Object {}

CountriesSchema.schema = {
    name: 'Countries',
    primaryKey: 'passportId',
    properties: {
        passportId: {type: 'string'},
        nationName: {type:'string', optional: true, default:''},
        code: {type:'string', optional: true, default:''},

    }
};

export default CountriesSchema;
import Countries from './CountriesDataBase/CountriesSchema';

realmInstance = new Realm({
            encryptionKey: getKey(),
            schema: [User]
})

As i said there are lot of schemas but i follow the same rule

@blagoev
Copy link
Contributor

blagoev commented Aug 6, 2020

Please fill out our issue template in full so we can see what the error is. Currently the issue does not contain any error.

@blagoev
Copy link
Contributor

blagoev commented Aug 6, 2020

My bad the error is in the title.
Could you fill out the issue template so we know which version and platforms this happens.

thanks

@rdamborsky
Copy link

rdamborsky commented Aug 14, 2020

I'm having same issue. I've seen it when I tried to upgrade to RN 62 few weeks ago (and so rolled back). Recently I upgraded to RN 63 and have it again.

Goals

Use classes with instance methods for my models, while connecting to realm.

Expected Results

Realm should open, data should be fetched correctly and instance methods work on instances of the models returned by realm.

Actual Results

Getting error in terminal:

TypeError: Reflect.construct requires the first argument be a constructor

Steps to Reproduce

Running an example below and using class instead of schema, in Realm.open.

Code Sample

class Base extends Realm.Object {
  debug() {
    log.debug('Area debug info', [`id=<${this.id}>`, `label=<${this.label}>`]);
  }
}

class AreaPlain extends Base {}

class Area extends Base {
  static schema = {
    name: 'Area',
    primaryKey: 'id',
    properties: {
      id: 'string',
      label: 'string'
    },
  };

  static all(realm) {
    return realm.objects(Area.schema.name).sorted('label');
  }
}

const area = new AreaPlain();
area.id = 'all';
area.label = 'All areas';

Realm.open([Area]);

Version of Realm and Tooling

  • Realm JS SDK Version: 6.0.4 (tried with 6.0.2 and 6.0.3 as well)
  • React Native: 0.63.2
  • Client OS & Version: Android 29
  • Which debugger for React Native: None

Libs versions at the point when my app worked (only the ones I feel are relevant). More details of the upgrade process are available at official upgrade guide for these two versions

Worked on:

  • react-native: 0.61.5
  • metro-react-native-babel-preset: 0.56.4
  • @babel/core: 7.10.3
  • @babel/plugin-proposal-decorators: 7.10.3
  • @babel/runtime: 7.10.3

Does not work on:

  • react-native 0.63.2
  • metro-react-native-babel-preset: 0.62.0
  • @babel/core: 7.11.1
  • @babel/plugin-proposal-decorators: 7.10.5
  • @babel/runtime: 7.11.2

While writing this report, I somehow managed to make it work. I'm still confused what happened, and why. And I'm hoping this is not false positive. My app now runs just fine with the versions of libs it was previously failing on.

What I did:

  1. downgraded some packages to older versions (see above for "worked on" list, except react-native)
  2. rm -rf node_modules && rm package-lock.json && npm i && react-native start --reset-cache
  3. cd android && ./gradlew clean && cd .. && react-native run-android
  4. reverted changes in package.json and repeated steps 2 and 3

@uendar could you try the steps above? At this point, it looks like some intermittent issue caused by caching / build inconsistencies.

@N3TC4T
Copy link

N3TC4T commented Aug 25, 2020

@rdamborsky can you try with yarn instead of npm ? I believe I had the same problem and changing to yarn fixed that.

@scousino
Copy link

I'm currently still having this issue on version 6.1.5

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants