andpor / react-native-sqlite-storage

Full featured SQLite3 Native Plugin for React Native (Android and iOS)
MIT License
2.74k stars 521 forks source link

Error: "... object ... meant to be immutable and has been frozen" #544

Closed rmacd closed 9 months ago

rmacd commented 1 year ago

Strange behaviour I came across when setting up / trying to access an sqlite instance:

 WARN  Possible Unhandled Promise Rejection (id: 0):
Error: You attempted to set the key `dblocation` with the value `"nosync"` on an object that is meant to be immutable and has been frozen.
    at throwOnImmutableMutation (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:2729:16)
    at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:102345:29)
    at call (native)
    at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:101708:24)
    at call (native)
    at apply (native)
    at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:101644:47)
    at tryCallTwo (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:61:9)
    at doResolve (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:216:25)
    at Promise (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:82:14)
    at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:101628:34)
    at ?anon_0_ (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:101295:93)
    at next (native)
    at asyncGeneratorStep (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:21711:26)
    at _next (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:21730:29)
    at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:21735:14)
    at tryCallTwo (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:61:9)
    at doResolve (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:216:25)
    at Promise (/Users/distiller/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:82:14)
    at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:21727:25)
    at apply (native)
    at getDBConnection (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:101300:24)
    at getEvents (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:101379:27)
    at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:178249:68)
    at commitHookEffectListMount (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:13876:38)
    at commitPassiveMountOnFiber (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:14926:44)
    at commitPassiveMountEffects_complete (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:14898:40)
    at commitPassiveMountEffects_begin (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:14888:47)
    at commitPassiveMountEffects (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:14878:40)
    at flushPassiveEffectsImpl (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:16224:34)
    at flushPassiveEffects (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:16181:43)
    at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:16069:34)
    at workLoop (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:64248:48)
    at flushWork (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:64227:28)
    at performWorkUntilDeadline (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:64441:48)
    at apply (native)
    at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:27439:26)
    at _callTimer (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:27354:17)
    at _callReactNativeMicrotasksPass (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:27387:17)
    at callReactNativeMicrotasks (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:27551:44)
    at __callReactNativeMicrotasks (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:2492:46)
    at anonymous (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:2292:45)
    at __guard (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:2472:15)
    at flushedQueue (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:2291:21)
    at invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.example.bugreport.mobile:2285:33)

failing code

const dbParams: DatabaseParams = {
    name: 'example-db',
    readOnly: false,
    location: 'default',
};

export const getDBConnection = async () => {
    return openDatabase(dbParams, () => {
    }, (e) => {
        throw Error(`Error in getDBConnection ${e.code} - ${e.message}`);
    });
};

working code

const dbParams: DatabaseParams = {
    name: 'example-db',
    readOnly: false,
    location: 'default',
};

export const getDBConnection = async () => {
    return openDatabase({...dbParams}, () => {
    }, (e) => {
        throw Error(`Error in getDBConnection ${e.code} - ${e.message}`);
    });
};

Cleaned build area, cleaned cached objects and error persisted across app reinstall.

Basically, as soon as I saw the log entry re expecting an immutable object, pass it via spread and it appears to behave. Is this expected behaviour?

Possibly related to #463

jinweizhe commented 9 months ago

怎么解决的???我也遇到了同样的问题

rmacd commented 9 months ago

If error is exact same, use spread as per 'working code' block.