realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.81k stars 577 forks source link

Gradle lint error with 12.10.0 and yarn errors with 12.11.1 #6787

Closed tmac24utm closed 4 months ago

tmac24utm commented 4 months ago

How frequently does the bug occur?

Always

Description

Let me preface by saying I assume this must be an issue with my setup, or there would be more reports. However, I can't seem to get by the lint error and it appears to be the patch for this that causes the other errors.

package.json ``` { "name": "project-name", "version": "0.0.1", "private": true, "scripts": { "android": "node ./scripts/android.mjs", "ios": "node ./scripts/ios.mjs", "start": "react-native start", "test": "yarn lint && yarn build && jest --ci --reporters=default --reporters=jest-junit", "test:coverage": "jest --coverage", "lint": "eslint . --ext .js,.jsx,.ts,.tsx", "build": "tsc --build tsconfig.json", "lintfix": "eslint . --ext .js,.ts,.tsx --fix", "install-ios": "bundle install && yarn pod-install" }, "dependencies": { "@formatjs/intl-getcanonicallocales": "2.3.0", "@formatjs/intl-locale": "4.0.0", "@formatjs/intl-numberformat": "8.10.3", "@formatjs/intl-pluralrules": "5.2.14", "@formatjs/intl-relativetimeformat": "11.2.14", "@native-html/table-plugin": "5.3.1", "@notifee/react-native": "7.8.2", "@react-native-async-storage/async-storage": "1.23.1", "@react-native-community/blur": "4.4.0", "@react-native-community/datetimepicker": "8.1.1", "@react-native-community/geolocation": "3.2.1", "@react-native-community/netinfo": "11.3.2", "@react-native-firebase/app": "20.1.0", "@react-native-firebase/firestore": "20.1.0", "@react-native-firebase/messaging": "20.1.0", "@react-native-picker/picker": "2.7.7", "@react-navigation/drawer": "6.7.0", "@react-navigation/material-top-tabs": "6.6.13", "@react-navigation/native": "6.1.17", "@react-navigation/stack": "6.4.0", "@rneui/base": "4.0.0-rc.8", "@rneui/themed": "4.0.0-rc.8", "@semantic-release/commit-analyzer": "13.0.0", "@semantic-release/release-notes-generator": "14.0.1", "@tanstack/react-query": "5.51.1", "appcenter": "5.0.1", "appcenter-analytics": "5.0.1", "appcenter-crashes": "5.0.1", "axios": "1.7.2", "core-js-pure": "3.37.1", "country-iso-3-to-2": "1.1.1", "currency-symbol-map": "5.1.0", "fp-ts": "2.16.8", "i18next": "23.11.5", "inversify": "6.0.2", "jwt-decode": "4.0.0", "libphonenumber-js": "1.11.4", "luxon": "3.4.4", "mime-types": "2.1.35", "path": "0.12.7", "prop-types": "15.8.1", "react": "18.3.1", "react-hooks-form-validator": "5.2.0", "react-i18next": "14.1.2", "react-native": "0.74.3", "react-native-collapsible": "1.6.1", "react-native-config": "1.5.2", "react-native-device-info": "11.1.0", "react-native-document-picker": "9.3.0", "react-native-file-viewer": "2.1.5", "react-native-fs": "2.20.0", "react-native-gesture-handler": "2.17.1", "react-native-get-random-values": "1.11.0", "react-native-image-picker": "7.1.2", "react-native-localize": "3.2.0", "react-native-logs": "5.1.0", "react-native-masked-text": "1.13.0", "react-native-pager-view": "6.3.3", "react-native-permissions": "4.1.5", "react-native-picker-select": "9.1.3", "react-native-reanimated": "3.14.0", "react-native-reanimated-carousel": "3.5.1", "react-native-render-html": "6.3.4", "react-native-safe-area-context": "4.10.8", "react-native-screens": "3.32.0", "react-native-size-matters": "0.4.2", "react-native-snackbar": "2.6.2", "react-native-sqlite-storage": "6.0.1", "react-native-svg": "15.3.0", "react-native-tab-view": "3.5.2", "react-native-vector-icons": "10.1.0", "react-native-video": "6.3.0", "react-native-webview": "13.10.5", "react-timestamp": "6.0.0", "realm": "12.10.0", "reflect-metadata": "0.2.2", "shorthash2": "1.0.3", "typedjson": "1.8.0", "uuid": "10.0.0" }, "devDependencies": { "@babel/core": "7.24.7", "@babel/eslint-parser": "7.24.7", "@babel/plugin-proposal-decorators": "7.24.7", "@babel/plugin-proposal-nullish-coalescing-operator": "7.18.6", "@babel/plugin-proposal-optional-chaining": "7.21.0", "@babel/plugin-transform-arrow-functions": "7.24.7", "@babel/plugin-transform-shorthand-properties": "7.24.7", "@babel/plugin-transform-template-literals": "7.24.7", "@babel/preset-env": "7.24.7", "@babel/runtime": "7.24.7", "@react-native/babel-preset": "0.74.85", "@react-native/eslint-config": "0.74.85", "@react-native/metro-config": "0.74.85", "@react-native/typescript-config": "0.74.85", "@semantic-release/git": "10.0.1", "@testing-library/jest-native": "5.4.3", "@testing-library/react-native": "12.5.1", "@types/jest-when": "3.5.5", "@types/luxon": "3.4.2", "@types/mime-types": "2.1.4", "@types/node": "20.14.10", "@types/randomstring": "1.3.0", "@types/react": "18.3.3", "@types/react-native-snap-carousel": "3.8.11", "@types/react-native-sqlite-storage": "6.0.5", "@types/react-native-video": "5.0.20", "@types/react-test-renderer": "18.3.0", "@types/uuid": "10.0.0", "babel-jest": "29.7.0", "babel-plugin-parameter-decorator": "1.0.16", "chalk": "5.3.0", "concurrently": "8.2.2", "eslint": "8.57.0", "eslint-plugin-ft-flow": "3.0.10", "hermes-eslint": "0.22.0", "inquirer": "10.0.1", "jest": "29.7.0", "jest-junit": "16.0.0", "jest-mock-axios": "4.7.3", "jest-mock-extended": "3.0.7", "jest-when": "3.6.0", "pod-install": "0.2.2", "prettier": "2.8.8", "randomstring": "1.3.0", "react-test-renderer": "18.3.1", "semantic-release": "24.0.0", "semantic-release-react-native": "1.10.0", "ts-jest": "29.2.2", "typescript": "5.5.3" }, "engines": { "node": ">=18" }, "jest-junit": { "outputDirectory": "./__tests__/report", "outputName": "junit.xml", "uniqueOutputName": "false", "classNameTemplate": "{classname}-{title}", "titleTemplate": "{classname}-{title}", "ancestorSeparator": " › ", "usePathForSuiteName": "true" }, "resolutions": { "semantic-release-react-native": "patch:semantic-release-react-native@1.10.0#~/.yarn/patches/semantic-release-react-native-npm-1.9.0-b79f01d5ce.patch", "react-native-vector-icons": "patch:react-native-vector-icons@10.1.0#~/.yarn/patches/react-native-vector-icons-npm-10.1.0-78f5c98868.patch", "realm": "patch:realm@12.10.0#~/.yarn/patches/realm-npm-12.10.0-d9181246d0.patch" }, "packageManager": "yarn@4.3.1" } ```

Issue on Version 12.10.0

I get a lint error when running gradle build.

Error:

> Task :realm:lintDebug FAILED
Lint found 1 errors, 0 warnings. First failure:

/Users/{name}/IdeaProjects/project-name/node_modules/realm/react-native/android/src/main/java/io/realm/react/RealmReactModule.java:98: Error: This declaration is opt-in and its usage should be marked with @com.facebook.react.common.annotations.FrameworkAPI or @OptIn(markerClass = com.facebook.react.common.annotations.FrameworkAPI.class) [UnsafeOptInUsageError from androidx.annotation.experimental]
        CallInvokerHolderImpl jsCallInvokerHolder = (CallInvokerHolderImpl) getReactApplicationContext().getCatalystInstance().getJSCallInvokerHolder();

Patch:

diff --git a/react-native/android/src/main/java/io/realm/react/RealmReactModule.java b/react-native/android/src/main/java/io/realm/react/RealmReactModule.java
index eda164794b888bebb9f74911cbd1fe6e16fbb55b..0b4cf1fa3e2d9d7648c897b41a551ba8df2618d1 100644
--- a/react-native/android/src/main/java/io/realm/react/RealmReactModule.java
+++ b/react-native/android/src/main/java/io/realm/react/RealmReactModule.java
@@ -22,9 +22,11 @@ import android.os.Handler;
 import android.os.HandlerThread;
 import android.util.Log;

+import androidx.annotation.OptIn;
 import com.facebook.react.bridge.JavaScriptContextHolder;
 import com.facebook.react.bridge.ReactApplicationContext;
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
+import com.facebook.react.common.annotations.FrameworkAPI;
 import com.facebook.react.module.annotations.ReactModule;
 import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
 import com.facebook.soloader.SoLoader;
@@ -91,6 +93,7 @@ class RealmReactModule extends ReactContextBaseJavaModule {
     }

     @Override
+    @OptIn(markerClass = FrameworkAPI.class)
     public void initialize() {
         // Pass the React Native jsCallInvokerHolder over to C++, so that we can access the invokeAsync
         // method which we use to flush the React Native UI queue whenever we call from C++ to JS.

Issue on Version 12.11.1

Removing the patch or reverting version fixes these errors

After updating, which still requires the patch (patch was updated to point at the new location under binding), I now get an out of memory error on my azure dev ops pipeline. This doesn't happen locally, so really we can assume it's nothing to do with Realm, but this only happened once I updated to this version. This also doesn't happen all of the time, for example two or three builds passed this morning, but 10+ others have failed. Related yarn issue: https://github.com/yarnpkg/berry/issues/3972

Error:

➤ YN0001: │ Error: Couldn't allocate enough memory
    at ZipFS.getBufferAndClose ([worker eval]:1:298046)
    at ZipFS.saveAndClose ([worker eval]:1:299036)
    at convertToZipWorker ([worker eval]:1:407956)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async MessagePort.<anonymous> ([worker eval]:1:409728)

Slightly different error (happened one time):

➤ YN0001: │ Error: realm@patch:realm@npm%3A12.11.1#~/.yarn/patches/realm-npm-12.11.1-b36e6a8058.patch::version=12.11.1&hash=2908f6: Couldn't allocate enough memory
    at Xi.getBufferAndClose (/home/vsts/work/1/s/.yarn/releases/yarn-4.3.1.cjs:149:196025)
    at Xi.saveAndClose (/home/vsts/work/1/s/.yarn/releases/yarn-4.3.1.cjs:149:197010)
    at _v.patchPackage (/home/vsts/work/1/s/.yarn/releases/yarn-4.3.1.cjs:710:1879)
    at async v (/home/vsts/work/1/s/.yarn/releases/yarn-4.3.1.cjs:199:1576)
    at async x (/home/vsts/work/1/s/.yarn/releases/yarn-4.3.1.cjs:199:1916)
    at async C (/home/vsts/work/1/s/.yarn/releases/yarn-4.3.1.cjs:199:3253)
    at async Nr.fetchPackageFromCache (/home/vsts/work/1/s/.yarn/releases/yarn-4.3.1.cjs:199:3374)
    at async _v.fetch (/home/vsts/work/1/s/.yarn/releases/yarn-4.3.1.cjs:710:1060)
    at async fE.fetch (/home/vsts/work/1/s/.yarn/releases/yarn-4.3.1.cjs:141:463)
    at async /home/vsts/work/1/s/.yarn/releases/yarn-4.3.1.cjs:210:11866

Pipeline .yml (fails at Install dependencies):

name: $(date:yyyyMMdd)$(rev:.r)

pr:
  - master

stages:
  - stage: Build
    jobs:
      jobs:
        - job: ci
          displayName: React Native CI
          pool:
            vmImage: ubuntu-latest
          steps:
            - checkout: self
              fetchDepth: 1

            - task: NodeTool@0
              displayName: Set up node version
              inputs:
                versionSource: 'spec'
                versionSpec: '>=18'

            - task: CmdLine@2
              displayName: Install dependencies
              inputs:
                script: |
                  yarn install --immutable

            - task: CmdLine@2
              displayName: Run tests
              inputs:
                script: |
                  yarn test --forceExit

I tried multiple different things to fix this, including setting NODE_OPTIONS to --max-old-space-size=6144 (ado agents have 7gb memory), changing node version, yarn version etc.

Separate 12.11.1 issue

I tried reverting to yarn 3.6.4 (the version used by new react native projects), and on this version, running yarn install causes it to "load" forever locally. This doesn't happen when trying yarn 3.6.4 on version 12.10.0

Stacktrace & log output

See description

Can you reproduce the bug?

Always

Reproduction Steps

I can always reproduce the lint error. The yarn memory error is inconsistent.

To reproduce the lint error

  1. npx @react-native-community/cli@latest init AwesomeProject
  2. cd AwesomeProject
  3. yarn add realm
  4. cd android
  5. ./gradlew build

To reproduce the yarn error

I assume this is a similar error, it just spins forever on install

  1. npx @react-native-community/cli@latest init AwesomeProject
  2. cd AwesomeProject
  3. yarn set version 3.6.4 (despite making a brand new project, my yarn version was set to 4.3.1. I'm sure this is a whole other issue)
  4. yarn add realm

ADO Error

  1. npx @react-native-community/cli@latest init AwesomeProject
  2. cd AwesomeProject
  3. yarn add realm
  4. yarn patch realm
  5. Follow the instructions to create the patch, and copy the changes I made in the patch above.
  6. Create an ADO pipeline using the yml above
  7. Run the pipeline

Version

12.10.0 & 12.11.1

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

macOS 14.5

Build environment

Yarn: 4.3.1 Gradle: 8.6

Cocoapods version

1.15.2

sync-by-unito[bot] commented 4 months ago

➤ PM Bot commented:

Jira ticket: RJS-2863

kneth commented 4 months ago

@tmac24utm Thank you for your detailed description

@kraenhansen Can you take a look once you are back?

kraenhansen commented 4 months ago

I've included a fix for the gradle lint error in #6737 and expect this to be included in the next upcoming release 👍

kraenhansen commented 4 months ago

I now get an out of memory error on my azure dev ops pipeline.

This could be due to the fact that we're now including more (and larger) prebuilt binaries in the archive uploaded to NPM since v12.11.0.

My suggestions would be to either: