callstack / haul

Haul is a command line tool for developing React Native apps, powered by Webpack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Realm crashes on create when using Haul

theminerymike opened this issue · comments

I've also reported this issue on Realm's github page as I'm not positive if the issue is more related to Realm or to Haul. You can follow it here realm/realm-js#2627

Goals

I am trying to get Realm working with Haul. It was working fine when I was using the react native packager but I'm not able to use the react native packager as it always crashes on load in Release with only a generic error message.

Expected Results

Successful item creation.

Actual Results

Screen Shot 2019-11-29 at 1 47 09 PM

TypeError: Cannot call a class constructor without |new|

create
    [native code]:0
<unknown>
    index.bundle?platform=ios&dev=true&minify=false:14530:29
write
    [native code]:0
<unknown>
    index.bundle?platform=ios&dev=true&minify=false:14529:26
invokeGuardedCallbackImpl
    index.bundle?platform=ios&dev=true&minify=false:187192:19
invokeGuardedCallback
    index.bundle?platform=ios&dev=true&minify=false:187370:40
invokeGuardedCallbackAndCatchFirstError
    index.bundle?platform=ios&dev=true&minify=false:187385:34
executeDispatch
    index.bundle?platform=ios&dev=true&minify=false:187516:46
executeDispatchesInOrder
    index.bundle?platform=ios&dev=true&minify=false:187541:24
executeDispatchesAndRelease
    index.bundle?platform=ios&dev=true&minify=false:187711:33
forEachAccumulated
    index.bundle?platform=ios&dev=true&minify=false:187692:16
runEventsInBatch
    index.bundle?platform=ios&dev=true&minify=false:187737:25
runExtractedPluginEventsInBatch
    index.bundle?platform=ios&dev=true&minify=false:187879:23
<unknown>
    index.bundle?platform=ios&dev=true&minify=false:189433:40
batchedUpdates$1
    index.bundle?platform=ios&dev=true&minify=false:203024:18
batchedUpdates
    index.bundle?platform=ios&dev=true&minify=false:189343:34
_receiveRootNodeIDEvent
    index.bundle?platform=ios&dev=true&minify=false:189432:21
receiveEvent
    index.bundle?platform=ios&dev=true&minify=false:189447:30
__callFunction
    index.bundle?platform=ios&dev=true&minify=false:139402:47
<unknown>
    index.bundle?platform=ios&dev=true&minify=false:139115:26
__guard
    index.bundle?platform=ios&dev=true&minify=false:139353:11
callFunctionReturnFlushedQueue
    index.bundle?platform=ios&dev=true&minify=false:139114:17
callFunctionReturnFlushedQueue
    [native code]:0

Steps to Reproduce

  1. git clone https://github.com/theminerymike/realm-haul.git
  2. yarn install
  3. cd ios && pod install
  4. cd .. && yarn haul start
  5. run in Xcode
  6. click the button "Click Me"

Code Sample

const Realm = require('realm')

class Setting {}
Setting.schema = {
    name: 'Setting',
    primaryKey: 'key',
    properties: {
        key: 'string',
        data: 'string'
    }
}

const realm = new Realm({
    schema: [
        Setting
    ]
})

realm.write(() => {
	realm.create('Setting', {key: 'test', data: 'test'}) // breaks here
})

Version of Realm and Tooling

  • Realm JS SDK Version: 3.4.2
  • Node or React Native: React Native 0.61.4 and Haul "@haul-bundler/cli": "^0.15.0"
  • Client OS & Version: macOS Catalina v10.15.1 running iPhone 11 simulator (also attempted on iPhone X simulator) on iOS 13.2.2

Are you using @haul-bundler/babel-preset-react-native?? If so, the classes are not compiled to functions so Realm is probably not instantiating Setting with new. You can try replacing class Setting { } with function Settings() { }.

Ha, no way, you're a lifesaver. Totally did the trick :)