Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.59k stars 597 forks source link

Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication #1460

Open MarcosSarges opened 1 year ago

MarcosSarges commented 1 year ago

I need help, I've tried to follow the documentation I always get this error:

Screenshot 2023-01-01 at 13 53 28

Error 1

 ERROR  Error: Requiring unknown module "undefined". If you are sure the module exists, try restarting Metro. You may also want to run `yarn` or `npm install`.
 ERROR  Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 10): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient.
        A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
 ERROR  Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 10): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient.
        A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

Error 2

 ERROR  TypeError: decorator is not a function. (In 'decorator(target, property, desc)', 'decorator' is an instance of Object)

npx react-native info :

System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1
    Memory: 69.64 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.17.3 - ~/.nvm/versions/node/v14.17.3/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.3/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.10.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
    Android SDK:
      API Levels: 21, 27, 28, 29, 30, 31, 32, 33
      Build Tools: 28.0.3, 29.0.0, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0, 33.0.0
      System Images: android-28 | Google ARM64-V8a Play ARM 64 v8a, android-31 | Google Play ARM 64 v8a
      Android NDK: 21.3.6528147
  IDEs:
    Android Studio: 2021.3 AI-213.7172.25.2113.9123335
    Xcode: 14.2/14C18 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.11 - /Users/marcossarges/.jenv/shims/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.1.0 => 18.1.0 
    react-native: 0.70.6 => 0.70.6 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

tsconfig.json

"experimentalDecorators": true,
"emitDecoratorMetadata": true

babel.config.js

module.exports = {
  presets: [
    'module:metro-react-native-babel-preset',
    '@babel/preset-typescript',
  ],
  plugins: [
    ['react-native-reanimated/plugin'],
    [
      'babel-plugin-root-import',
      {
        rootPathPrefix: '~',
        rootPathSuffix: 'src',
      },
    ],
    'babel-plugin-transform-typescript-metadata',
    ['@babel/plugin-proposal-decorators', { legacy: true }],
    ['@babel/plugin-proposal-class-properties', { loose: true }],
  ],
};

package.json

{
  "name": "oftalmoapp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
  },
  "dependencies": {
    "@gorhom/bottom-sheet": "^4",
    "@nozbe/watermelondb": "^0.24.0",
    "@react-native-community/async-storage": "^1.12.1",
    "@react-navigation/bottom-tabs": "^6.4.0",
    "@react-navigation/drawer": "^6.5.0",
    "@react-navigation/native": "^6.0.13",
    "@react-navigation/stack": "^6.3.2",
    "axios": "^1.1.2",
    "polished": "^4.2.2",
    "react": "18.1.0",
    "react-native": "0.70.6",
    "react-native-gesture-handler": "^2.8.0",
    "react-native-reanimated": "^2.11.0",
    "react-native-reanimated-carousel": "^3.1.5",
    "react-native-safe-area-context": "^4.4.1",
    "react-native-screens": "^3.18.0",
    "react-native-svg": "^13.4.0",
    "react-native-text-input-mask": "^3.1.4",
    "reflect-metadata": "^0.1.13",
    "styled-components": "^5.3.6"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/plugin-proposal-class-properties": "^7.18.6",
    "@babel/plugin-proposal-decorators": "^7.20.7",
    "@babel/preset-typescript": "^7.18.6",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "@tsconfig/react-native": "^2.0.2",
    "@types/jest": "^29.1.2",
    "@types/react": "^18.0.21",
    "@types/react-native": "^0.70.4",
    "@types/react-test-renderer": "^18.0.0",
    "@types/styled-components": "^5.1.26",
    "@types/styled-components-react-native": "^5.1.3",
    "@typescript-eslint/eslint-plugin": "^5.39.0",
    "@typescript-eslint/parser": "^5.39.0",
    "babel-jest": "^26.6.3",
    "babel-plugin-module-resolver": "^4.1.0",
    "babel-plugin-root-import": "^6.6.0",
    "babel-plugin-transform-typescript-metadata": "^0.3.2",
    "eslint": "^8.0.1",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-config-airbnb-base": "^15.0.0",
    "eslint-config-airbnb-typescript": "^17.0.0",
    "eslint-config-standard-with-typescript": "^23.0.0",
    "eslint-import-resolver-babel-plugin-root-import": "^1.1.1",
    "eslint-import-resolver-typescript": "^3.5.2",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-jsx-a11y": "^6.6.1",
    "eslint-plugin-n": "^15.0.0",
    "eslint-plugin-prettier": "^4.2.1",
    "eslint-plugin-promise": "^6.0.0",
    "eslint-plugin-react": "^7.31.8",
    "eslint-plugin-react-hooks": "^4.6.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "0.72.3",
    "prettier": "^2.7.1",
    "react-test-renderer": "18.1.0",
    "typescript": "^4.8.4"
  },
  "jest": {
    "preset": "react-native",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json",
      "node"
    ]
  }
}

index.js

import 'reflect-metadata';
import { AppRegistry, Platform } from 'react-native';
import App from './src/App';
import { name as appName } from './app.json';

import { Database } from '@nozbe/watermelondb';
import SQLiteAdapter from '@nozbe/watermelondb/adapters/sqlite';

import { schemas } from './src/watermelon/schema';
import { modelClasses } from './src/watermelon/model';
import { migrations } from './src/watermelon/migrations';

const adapter = new SQLiteAdapter({
  dbName: 'oftalmoapp',
  schema: schemas,
  migrations,
  jsi: Platform.OS === 'ios',
  onSetUpError: error => {
    console.log(error);
  },
});

export const database = new Database({
  adapter,
  modelClasses,
});

AppRegistry.registerComponent(appName, () => App);
KrisLau commented 1 year ago

It's something to do with your setup, probably the schema. Read through the solutions for similar issues: