xaviergonz / mobx-keystone

A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more

Home Page:https://mobx-keystone.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue when migrating from v0.54.0 to v0.55.0

AshwinDeTaeye opened this issue · comments

When updating the mobx-keystone package in a react native app from v0.54.0 to v0.55.0 i have the following error:

ERROR    TypeError: undefined is not a function, js engine: hermes
ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication), js engine: hermes
ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication), js engine: hermes

I have previously migrated most of my other apps without issue ( node, electron )
It seems to only be with react native.

babel.config.js

module.exports = {
  presets: [
    // If you use TypeScript
    ["@babel/preset-typescript", { allowDeclareFields: true }],
    [
      "module:metro-react-native-babel-preset",
      {
        unstable_disableES6Transforms: true,
      },
    ],
  ],
  env: {
    production: {},
  },
  plugins: [
    // MobX 5/6
    [
      "@babel/plugin-proposal-decorators",
      {
        legacy: true,
      },
    ],
    ["@babel/plugin-proposal-class-properties", { loose: true }],
    ["@babel/plugin-proposal-optional-catch-binding"],
  ],
}

package.json

    "react-native": "^0.63.4",
    "react": "16.14.0",
    "mobx": "^6.6.1",
    "mobx-keystone": "^0.55.0",
    "mobx-keystone-persist": "^1.2.0",
    "mobx-react": "^7.5.2",
    "mobx-react-lite": "^3.4.0",

Does anybody have similar experiences?
All versions from 0.55.0 on have this issue.

Kr,

does it also happen if you use another engine instead of hermes?

When i set /android/build/build.gradle to:

project.ext.react = [
enableHermes: false, // clean and rebuild if changing
]

It stays the same. I also updated the hermes engine from 0.5.2 to 0.11.0 without effect.

If you edit this line from the package.json inside node_modules/mobx-keystone to this:
"react-native": "./src/index.ts",
does it work then?

With Hermes 'off' and "react-native": "./src/index.ts", it gives following error:

mobx-keystone@0.69.5 & 0.60.5 without Hermes

ERROR    TypeError: (0, _mobxKeystone.prop_dateString) is not a function. (In '(0, _mobxKeystone.prop_dateString)()', '(0, _mobxKeystone.prop_dateString)' is undefined)
ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)

For this, I should refactor quite a bit, I've done it before in other migrations. I'll do it in the next week and try again.
However the two last errors seem similar to the ones before.

When I set Hermes back on I have the same error as initially
mobx-keystone@0.69.5 & 0.60.5 with Hermes

ERROR    TypeError: undefined is not a function, js engine: hermes
ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication), js engine: hermes
ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication), js engine: hermes

mobx-keystone@0.50.0

error: Error: While trying to resolve module `mobx-keystone` from file `/home/u/git/CamePrinterLast/app/models/root-store.ts`, the package `/home/u/git/CamePrinterLast/node_modules/mobx-keystone/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved...

Logic, since the src doesn't exist in 0.50

Thanks for the support yet, your package has been very helpful since the start!

What if besides the other change you also set "sideEffects": true in the package.json?

I just published v0.69.7 which has some changes that make it work for expo (the previous one was not), could you check if it works now?

It's the same with 0.69.7

ERROR    TypeError: (0, _mobxKeystone.prop_dateString) is not a function. (In '(0, _mobxKeystone.prop_dateString)()', '(0, _mobxKeystone.prop_dateString)' is undefined)
ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
  • Hermes off

In node_modules/mox-keystone package.json:

  • "sideEffects": true
  • "react-native": "./src/index.ts"