Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'object type 'f' not found in schema' occurs when updating the application via code push appcenter #6777

Closed
bac95ts opened this issue Jul 4, 2024 · 5 comments

Comments

@bac95ts
Copy link

bac95ts commented Jul 4, 2024

How frequently does the bug occur?

Always

Description

When updating the app release via CodePush on App Center, I encounter the error 'object type 'f' not found in schema'. This error does not occur when updating the app through TestFlight or the App Store.
After updating bundle js from code push I see (use source map):

stack:

.../node_modules/realm/dist/ClassMap.js:132:26"
.../node_modules/realm/dist/ClassMap.js:156:33"
.../node_modules/realm/dist/Realm.js:677:58"
.../node_modules/@realm/react/dist/index.cjs:151:45"

Has anyone experienced a similar issue or can provide assistance?

const config: Realm.Configuration = {
  schema: [
    UserEntity,
     ...
  ],
  schemaVersion: 2,
  deleteRealmIfMigrationNeeded: true,
  onFirstOpen(realm: Realm) {
    UserEntity.createDefaultUsers(realm);
  },
};

export const {RealmProvider, useQuery, useObject, useRealm} =
  createRealmContext(config);

<RealmProvider path={`abc.realm`}>
      ...
</RealmProvider>

Stacktrace & log output

'Unhandled JS Exception: Error: Object type 'l' not found in schema.

This error is located at:
    in Unknown
    in Unknown
    in RCTView
    in Unknown
    in Unknown
    i..., stack:
value@1477:1091
value@1477:1740
value@1458:8114
p@1435:1644
anonymous@1435:2066
useMemo@239:50342
anonymous@24:6133
anonymous@1435:2043
anonymous@1912:273
Ir@239:43660
Ta@239:95329
yi@239:86333
vi@239:86235
mi@239:86000
ci@239:82953
pt@239:27146
ri@239:79605
ol@239:48909
C@1435:1393
anonymous@1482:1212
'
*** First throw call stack:
(
	0   CoreFoundation                      0x00000001804ae0f8 __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x0000000180087db4 objc_exception_throw + 56
	2   ChatSampleAppStaging                0x0000000104a53f1c RCTFormatError + 0
	3   ChatSampleAppStaging                0x00000001047def48 -[RCTExceptionsManager reportFatal:stack:exceptionId:extraDataAsJSON:] + 488
	4   ChatSampleAppStaging                0x00000001047df75c -[RCTExceptionsManager reportException:] + 1308
	5   CoreFoundation                      0x00000001804b4720 __invoking___ + 144
	6   CoreFoundation                      0x00000001804b1a84 -[NSInvocation invoke] + 276
	7   CoreFoundation                      0x00000001804b1d1c -[NSInvocation invokeWithTarget:] + 60
	8   ChatSampleAppStaging                0x0000000104a836b0 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 388

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

"realm": 12.6.2

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

ios

Build environment

Which release for React Native: ..

Cocoapods version

1.15.2

Copy link

sync-by-unito bot commented Jul 4, 2024

➤ PM Bot commented:

Jira ticket: RJS-2857

@bac95ts
Copy link
Author

bac95ts commented Jul 22, 2024

in file .../node_modules/realm/dist/ClassMap.js . I add comments as follows:

if (typeof arg === "string") {

            console.log(`Log 1 arg: ${arg}`);
            const mappingKeys = Object.keys(this.mapping);
            console.log(`Log 2 this.mapping.keys: ${JSON.stringify(mappingKeys)}`);
           
            const constructor = this.mapping[arg];
            if (!constructor) {
                throw new Error(`Object type '${arg}' not found in schema.`);
            }
            return constructor;
        }

After updating bundle code push:

Log 1 arg: l
Log 2 this.mapping.keys: ["UserEntity",...]

Error: Object type 'l' not found in schema

@bac95ts
Copy link
Author

bac95ts commented Jul 22, 2024

I think the problem is minify/obfuscator bundle Code Push process

@bac95ts
Copy link
Author

bac95ts commented Jul 29, 2024

I found the cause of this error, this configuration solved my problem. In metro.config.js, add minifierConfig like below:

// metro.config.js
const { getDefaultConfig } = require('metro-config');

module.exports = (async () => {
  const {
    resolver: { sourceExts, assetExts },
  } = await getDefaultConfig();
  return {
    transformer: {
      getTransformOptions: async () => ({
        transform: {
          experimentalImportSupport: false,
          inlineRequires: true,
        },
      }),
      minifierConfig: {
        mangle: {
          // Keep the names of the schemas to avoid errors
          keep_classnames: true,
          keep_fnames: true,
        },
        output: {
          comments: false,
        },
      },
    },
    resolver: {
      sourceExts: [...sourceExts, 'cjs'],
    },
  };
})();

@bac95ts bac95ts closed this as completed Jul 29, 2024
@kraenhansen
Copy link
Member

@bac95ts happy this got resoved! Thanks for updating the issue 👍

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants