I have a React Native app and the app was working fine but then I started to decouple the functions that communicate with the backend through some object oriented programming and now when I run the app I get the following error and I can’t for the life of me figure out what is wrong:
This is what appears on the Android emulator:
cannot use the reserved word 'private' as a parameter name in strict mode
cannot use the reserved word 'private' as a parameter name in strict mode
no stack
no stack
This is the error that appears in Logcat:
Exception in native call from JS
com.facebook.react.devsupport.JSException: Cannot use the reserved word 'private' as a parameter name in strict mode.
at com.facebook.jni.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
at java.lang.Thread.run(Thread.java:1012)
Caused by: com.facebook.jni.CppException: Cannot use the reserved word 'private' as a parameter name in strict mode.
no stack
... 8 more
2024-06-06 07:41:00.282 3429-7954 ReactNativeJNI net.package E Attempting to call JS function on a bad application bundle: HMRClient.setup()
2024-06-06 07:41:00.285 3429-7954 unknown:ReactNative net.package E Exception in native call
java.lang.RuntimeException: Attempting to call JS function on a bad application bundle: HMRClient.setup()
at com.facebook.jni.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
at java.lang.Thread.run(Thread.java:1012)
2024-06-06 07:41:00.285 3429-7954 ReactNativeJNI net.package E Attempting to call JS function on a bad application bundle: AppRegistry.runApplication()
2024-06-06 07:41:00.287 3429-7954 unknown:ReactNative net.package E Exception in native call
java.lang.RuntimeException: Attempting to call JS function on a bad application bundle: AppRegistry.runApplication()
at com.facebook.jni.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
at java.lang.Thread.run(Thread.java:1012)
This is my package.json:
{
"name": "pacakge-name",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"lint": "eslint .",
"start": "react-native start",
"test": "jest",
"update-types": "source .env && npx supabase gen types typescript --project-id "$PROJECT_REF" > src/types/database.d.ts && npx eslint --fix ."
},
"dependencies": {
"@react-native-async-storage/async-storage": "^1.21.0",
"@react-native-firebase/app": "^18.9.0",
"@react-native-firebase/messaging": "^18.9.0",
"@react-navigation/bottom-tabs": "^6.5.11",
"@react-navigation/native": "^6.1.9",
"@react-navigation/native-stack": "^6.9.17",
"@react-navigation/stack": "^6.3.20",
"@reduxjs/toolkit": "^1.9.7",
"@supabase/storage-js": "^2.5.5",
"@supabase/supabase-js": "^2.38.4",
"@tensorflow/tfjs": "^4.0.0",
"@tensorflow/tfjs-react-native": "^1.0.0",
"@urql/core": "^4.2.0",
"base-64": "^1.0.0",
"crypto": "^1.0.1",
"graphql": "^16.8.1",
"htmlparser2": "^9.0.0",
"jpeg-js": "^0.3.6",
"prop-types": "^15.8.1",
"react": "18.2.0",
"react-native": "0.72.7",
"react-native-aes-crypto": "^3.0.1",
"react-native-background-fetch": "^4.2.1",
"react-native-config": "^1.5.1",
"react-native-country-codes-picker": "^2.3.4",
"react-native-device-info": "^10.12.0",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^2.15.0",
"react-native-keychain": "^8.1.2",
"react-native-localize": "^3.0.3",
"react-native-paper": "^5.11.1",
"react-native-rsa-native": "^2.0.5",
"react-native-safe-area-context": "^4.9.0",
"react-native-screens": "^3.27.0",
"react-native-url-polyfill": "^2.0.0",
"react-native-vector-icons": "^10.0.2",
"react-redux": "^8.1.3",
"resend": "^2.0.0"
},
"devDependencies": {
"@babel/plugin-transform-flow-strip-types": "^7.23.3",
"@babel/preset-env": "^7.23.3",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@babel/runtime": "^7.20.0",
"@jest/globals": "^29.7.0",
"@parcel/watcher": "^2.3.0",
"@react-native/eslint-config": "^0.72.2",
"@react-native/metro-config": "^0.72.11",
"@testing-library/jest-native": "^5.4.3",
"@testing-library/react-native": "^12.4.0",
"@tsconfig/react-native": "^3.0.0",
"@types/base-64": "^1.0.2",
"@types/jest": "^29.5.11",
"@types/react": "^18.0.24",
"@types/react-native-dotenv": "^0.2.1",
"@types/react-native-vector-icons": "^6.4.18",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.7.0",
"babel-plugin-module-resolver": "^5.0.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"eslint": "^8.57.0",
"eslint-import-resolver-babel-module": "^5.3.2",
"eslint-plugin-import": "^2.29.0",
"jest": "^29.7.0",
"jest-config": "^29.7.0",
"metro-config": "^0.80.3",
"metro-react-native-babel-preset": "0.76.8",
"prettier": "^2.4.1",
"react-native-dotenv": "^3.4.9",
"react-test-renderer": "18.2.0",
"supabase": "^1.112.0",
"ts-jest": "^29.1.1",
"typescript": "^4.8.4"
},
"engines": {
"node": ">=16"
}
}
Here is an example of the object oriented programming that I used in a service file:
import { User } from '@supabase/supabase-js';
import { adminsRepo } from 'lib/repositories/supabase/AdminsRepo';
import { AuthRepo, IAuthRepo } from 'lib/repositories/supabase/AuthRepo';
import { confidantsRepo } from 'lib/repositories/supabase/ConfidantsRepo';
import { membersRepo } from 'lib/repositories/supabase/MembersRepo';
import { Role } from 'types/common';
class AuthService {
constructor(private authRepo: IAuthRepo) {}
async signup(email: string, password: string, phone: string) {
return await this.authRepo.signup(email, password, phone);
}
async login(email: string, password: string) {
return await this.authRepo.login(email, password);
}
async getUserRoles(user: User) {
const roles: Role[] = [];
if (await adminsRepo.check(user)) {
roles.push('admin');
}
if (await membersRepo.check(user)) {
roles.push('member');
}
if (await confidantsRepo.check(user)) {
roles.push('confidant');
}
return roles;
}
}
export const authService = new AuthService(new AuthRepo());
And here is an example of a repo
file:
import { User } from '@supabase/supabase-js';
import { supabase } from 'lib/repositories/supabase/client';
import { HandleBackendErrors } from 'utils';
export interface IAuthRepo {
signup(email: string, password: string, phone: string): Promise<User>;
login(email: string, password: string): Promise<User>;
}
@HandleBackendErrors
export class AuthRepo implements IAuthRepo {
async signup(email: string, password: string, phone: string): Promise<User> {
const { data, error } = await supabase.auth.signUp({
email,
password,
phone,
});
if (error || !data.user) {
throw error;
}
return data.user;
}
async login(email: string, password: string): Promise<User> {
const { data, error } = await supabase.auth.signInWithPassword({
email,
password,
});
if (error || data.user) {
throw error;
}
return data.user;
}
async emailExists(email: string) {
const { data, error } = await supabase
.from('users')
.select('*')
.eq('email', email);
if (error) {
throw error;
}
return data && data.length > 0;
}
}
export const authRepo = new AuthRepo();
I removing all the `private keywords from all the typescript files but that didn’t work. I tried reverting to the main branch and running the app again and it worked but I cannot figure out why after I made the changes this happened. To be honest, I made a lot of changes without running the code. But all the changes were refactors of the current code.
Here is a screenshot of the emulator: