mobx-keystone icon indicating copy to clipboard operation
mobx-keystone copied to clipboard

Issue when migrating from v0.54.0 to v0.55.0

Open AshwinDeTaeye opened this issue 2 years ago • 7 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,

AshwinDeTaeye avatar Jul 26 '22 12:07 AshwinDeTaeye

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

xaviergonz avatar Jul 26 '22 14:07 xaviergonz

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.

AshwinDeTaeye avatar Jul 26 '22 15:07 AshwinDeTaeye

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?

xaviergonz avatar Jul 27 '22 21:07 xaviergonz

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

[email protected] & 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 [email protected] & 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

[email protected]

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!

AshwinDeTaeye avatar Jul 29 '22 12:07 AshwinDeTaeye

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

xaviergonz avatar Jul 29 '22 13:07 xaviergonz

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?

xaviergonz avatar Jul 30 '22 18:07 xaviergonz

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"

AshwinDeTaeye avatar Aug 01 '22 13:08 AshwinDeTaeye