question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataStore.clear() Error : [TypeError: undefined is not a function]

See original GitHub issue

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

DataStore

Amplify Categories

Not applicable

Environment information

# Put output below this line

  System:
    OS: Windows 10 10.0.22000
    CPU: (12) x64 11th Gen Intel(R) Core(TM) i5-11400F @ 2.60GHz
    Memory: 3.14 GB / 15.84 GB
  Binaries:
    Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.18 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.18.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (108.0.1462.46)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @alessiocancian/react-native-actionsheet: ^3.2.0 => 3.2.0 
    @aws-amplify/datastore-storage-adapter: ^2.0.5 => 2.0.5 
    @aws-amplify/pushnotification: ^5.0.5 => 5.0.5 
    @aws-sdk/client-codeguruprofiler: ^3.226.0 => 3.226.0 
    @aws-sdk/client-xray: ^3.226.0 => 3.226.0 
    @azure/core-asynciterator-polyfill: ^1.0.2 => 1.0.2 
    @babel/core: ^7.20.5 => 7.20.5 
    @babel/runtime: ^7.20.6 => 7.20.6 
    @react-native-async-storage/async-storage: ^1.17.11 => 1.17.11 
    @react-native-community/eslint-config: ^3.2.0 => 3.2.0 
    @react-native-community/netinfo: ^9.3.7 => 9.3.7 
    @react-native-community/push-notification-ios: ^1.10.1 => 1.10.1 (1.0.3)
    @react-navigation/bottom-tabs: ^6.5.0 => 6.5.0 
    @react-navigation/native: ^6.1.0 => 6.1.0 
    @react-navigation/native-stack: ^6.9.5 => 6.9.5 
    @react-navigation/stack: ^6.3.8 => 6.3.8 
    @reduxjs/toolkit: ^1.9.1 => 1.9.1 
    @reduxjs/toolkit-query:  1.0.0 
    @reduxjs/toolkit-query-react:  1.0.0 
    @tsconfig/react-native: ^2.0.3 => 2.0.3 
    @types/jest: ^29.2.4 => 29.2.4 
    @types/react: ^18.0.26 => 18.0.26 
    @types/react-native: ^0.70.8 => 0.70.8 
    @types/react-test-renderer: ^18.0.0 => 18.0.0 
    HelloWorld:  0.0.1 
    amazon-cognito-identity-js: ^6.0.1 => 6.0.1 (5.2.12)
    amplify: ^0.0.11 => 0.0.11 
    aws-amplify: ^5.0.5 => 5.0.5 
    babel-jest: ^29.3.1 => 29.3.1 
    crypto-js: ^4.1.1 => 4.1.1 (3.3.0)
    eslint: ^8.29.0 => 8.29.0 
    hermes-inspector-msggen:  1.0.0 
    jest: ^29.3.1 => 29.3.1 
    metro-react-native-babel-preset: ^0.73.4 => 0.73.4 (0.67.0)
    moment: ^2.29.4 => 2.29.4 
    react: ^17.0.2 => 17.0.2 
    react-native: 0.68.2 => 0.68.2 
    react-native-blob-util: ^0.17.0 => 0.17.0 
    react-native-chart-kit: ^6.12.0 => 6.12.0 
    react-native-curved-bottom-bar: ^2.1.4 => 2.1.4 
    react-native-date-picker: ^4.2.6 => 4.2.6 
    react-native-element-dropdown: ^2.5.0 => 2.5.0 
    react-native-gesture-handler: ^2.8.0 => 2.8.0 
    react-native-get-random-values: ^1.8.0 => 1.8.0 
    react-native-image-picker: ^4.10.2 => 4.10.2 
    react-native-image-zoom-viewer: ^3.0.1 => 3.0.1 
    react-native-linear-gradient: ^2.6.2 => 2.6.2 
    react-native-modal: ^13.0.1 => 13.0.1 
    react-native-pager-view: ^6.1.2 => 6.1.2 
    react-native-pdf: ^6.6.2 => 6.6.2 
    react-native-reanimated: ^2.13.0 => 2.13.0 
    react-native-safe-area-context: ^4.4.1 => 4.4.1 
    react-native-scoped-storage: ^1.9.3 => 1.9.3 
    react-native-screens: ^3.18.2 => 3.18.2 
    react-native-splash-screen: ^3.3.0 => 3.3.0 
    react-native-sqlite-storage: ^6.0.1 => 6.0.1 
    react-native-svg: ^13.6.0 => 13.6.0 
    react-native-switch-selector: ^2.3.0 => 2.3.0 
    react-native-touch-id: ^4.4.1 => 4.4.1 
    react-native-url-polyfill: ^1.3.0 => 1.3.0 
    react-native-uuid: ^2.0.1 => 2.0.1 
    react-native-vision-camera: ^2.15.2 => 2.15.2 
    react-native-webview: ^11.26.0 => 11.26.0 
    react-redux: ^8.0.5 => 8.0.5 
    react-test-renderer: 17.0.2 => 17.0.2 
    redux: ^4.2.0 => 4.2.0 
    redux-persist: ^6.0.0 => 6.0.0 
    redux-persist/integration/react:  undefined ()
    redux-thunk: ^2.4.2 => 2.4.2 
    typescript: ^4.9.4 => 4.9.4 
  npmGlobalPackages:
    @aws-amplify/cli: 9.1.0
    @react-native-community/cli-platform-android: 7.0.1
    eas-cli: 0.48.2
    expo-cli: 5.2.0
    npm: 8.18.0
    react-native-cli: 2.0.1
    react-native-paper: 4.12.0
    react-native-webview: 11.17.2
    yarn: 1.22.18

Describe the bug

I am using “aws-amplify”: “^4.3.43” , “@aws-amplify/cli”: “^9.1.0”, [TypeError: undefined is not a function] When Calling Datastore.clear() function

Expected behavior

Expected to clear local data, But it doesn’t seams to clear

Reproduction steps

DataStore.clear();

Code Snippet

// Put your code below this line.

const onSignOut = async () => { try {

  await DataStore.clear()
  await Auth.signOut().catch(error => {
    Alert.alert(error.message);
  });
} catch (error) {
  console.log('log Datastore: ', error)
}

};

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
dpilchcommented, Dec 20, 2022

Work Around (TLDR)

Add the polyfill to your dependencies.

npm install --save promise.allsettled

Then add the following to somewhere near the root of your app (such as index.js).

import allSettled from 'promise.allsettled';

allSettled.shim();

Explanation

The issue is that the polyfill for Promise used by Hermes does not include Promise.allSettled (or Promise.any). react-native@0.70.6 added support for Promise.allSettled (and Promise.any). However, React Native will use the Promise polyfill from Hermes if it is available (according to https://github.com/facebook/react-native/issues/35363#issuecomment-1335298726) resulting in Promise.allSettled still missing when using Hermes. This will be fixed in react-native@0.71.x (https://github.com/facebook/hermes/issues/766#issuecomment-1340085132).

The workaround suggested in https://github.com/facebook/hermes/issues/766#issuecomment-1182737719 will unblock current versions of React Native.

The workaround is clearly not a great experience, so we will be looking into a proper fix.

2reactions
chrisbonifaciocommented, Dec 15, 2022

@jeromeheissler and @imdkbj I noticed you are both calling DataStop.stop before DataStore.clear. Can you try just calling DataStore.clear? and let me know if the issue persists?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Amplify error: [TypeError: undefined is not an object ...
I'm currently developing a React Native application from scratch with Expo CLI. I set the backend with AWS Amplify. Deploy and pull are...
Read more >
javascript api 3.11 query task error " undefined is not a function"
Solved: Can someone please help me with the code below. I have been struggling to find why I am getting "Uncaught TypeError: undefined...
Read more >
DataStore | amplify-js
Clears all data from storage and removes all data, schema info, other initialization details, and then stops DataStore. That said, reinitialization is required ......
Read more >
How to Fix “Promise resolver undefined is not a function” in ...
If you're running into the “Promise resolver undefined is not a function” error, your code may look like this new Promise() instead of...
Read more >
Using AWS Amplify API with DataStore - YouTube
In this live stream, Kilo Loco shows how to create a GraphQL mutation document from AWS Amplify API that is compatible with Amplify ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found