-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
DataStore.clear() Error : [TypeError: undefined is not a function] #10764
Comments
Hi @santhoshpriya0715 👋 thanks for raising this issue! While I try to reproduce the error, can you try deleting your Let me know if the issue persists afterwards. |
Same problem with version 5.0.5 of aws-amplify. I've tried to stop datastore before clear with that code : const logger = new Logger('App');
export default function App() {
const [loading, setLoading] = useState(false);
useEffect(() => {
setLoading(true);
logger.info('stop');
DataStore.stop()
.then(() => {
logger.info('clear');
return DataStore.clear();
})
.then(() => {
logger.info('start');
return DataStore.start();
})
.then(() => {
logger.info('started');
setLoading(false);
})
.catch(err => {
logger.error('unbable to clear DataStore', err);
});
}, []);
return loading ? (
<View />
) : (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<NavigationContainer>
<Route />
</NavigationContainer>
</PersistGate>
</Provider>
);
} In the log i can see :
|
This issue in @aws-amplify/DataStore latest version
|
In both case. DataStore.clear(), DatasStore.stop()
On Wed, 14 Dec, 2022, 4:48 pm Santhosh Priya, ***@***.***>
wrote:
… This error came based on @aws-amplify/cli latest version
On Wed, 14 Dec, 2022, 3:41 pm Jérôme Heissler, ***@***.***>
wrote:
> Same problem with version 5.0.5 of aws-amplify.
>
> I've tried to stop datastore before clear with that code :
>
> const logger = new Logger('App');export default function App() {
> const [loading, setLoading] = useState(false);
> useEffect(() => {
> setLoading(true);
> logger.info('stop');
> DataStore.stop()
> .then(() => {
> logger.info('clear');
> return DataStore.clear();
> })
> .then(() => {
> logger.info('start');
> return DataStore.start();
> })
> .then(() => {
> logger.info('started');
> setLoading(false);
> })
> .catch(err => {
> logger.error('unbable to clear DataStore', err);
> });
> }, []);
>
> return loading ? (
> <View />
> ) : (
> <Provider store={store}>
> <PersistGate loading={null} persistor={persistor}>
> <NavigationContainer>
> <Route />
> </NavigationContainer>
> </PersistGate>
> </Provider>
> );}
>
> In the log i can see :
>
> BUNDLE ./index.js
>
> LOG Running "myapp" with {"rootTag":51,"initialProps":{}}
> LOG [INFO] 09:10.750 App - stop
> ERROR [ERROR] 09:10.805 App - unbable to clear DataStore [TypeError: undefined is not a function]
>
> —
> Reply to this email directly, view it on GitHub
> <#10764 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AUO2QDSDXNMSM2B67AHITS3WNGMMXANCNFSM6AAAAAAS4BIJD4>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
Yes, I tried what you say but its not working. |
Facing the same.
import React from 'react';
import { Provider } from 'react-redux';
import Toast from 'react-native-toast-notifications';
import { PersistGate } from 'redux-persist/integration/react';
import { Amplify, AuthModeStrategyType, DataStore, Hub } from 'aws-amplify';
import { SQLiteAdapter } from '@aws-amplify/datastore-storage-adapter/SQLiteAdapter';
import { store, persistor } from './redux/store';
import './translation';
import './utils/notification';
import './utils/interceptors';
import { handleLogout } from './utils/logout';
import awsconfig from './aws-exports';
import App from './App';
Amplify.configure({
...awsconfig,
DataStore: {
authModeStrategyType: AuthModeStrategyType.MULTI_AUTH,
},
});
// Amplify.Logger.LOG_LEVEL = 'DEBUG';
DataStore.configure({
storageAdapter: SQLiteAdapter,
errorHandler: error => {
console.warn('DataStore error', error);
},
});
Hub.listen('auth', async data => {
switch (data.payload.event) {
case 'signOut':
try {
await handleLogout();
await DataStore?.stop?.();
await DataStore?.clear?.();
} catch (error) {
console.log('Hub signOut error', error);
}
break;
default:
break;
}
});
const ClientApp = () => {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<App />
<Toast ref={ref => (global.toast = ref)} />
</PersistGate>
</Provider>
);
};
export default ClientApp; import { Dimensions, Platform } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { actions as authActions, deleteFCMToken } from '../redux/auth';
import { actions as projectActions } from '../redux/project';
import { actions as homeActions } from '../redux/home';
import { store } from '../redux/store';
import { startWatch } from './location';
const { width, height } = Dimensions.get('screen');
export const handleLogout = async () => {
try {
const data = {
platform: Platform.OS,
version: Platform.Version,
width,
height,
};
startWatch('unsubscribe');
await store.dispatch(deleteFCMToken(data));
store.dispatch(authActions.setLogOut());
store.dispatch(homeActions.resetData());
store.dispatch(projectActions.resetData());
await AsyncStorage.setItem('TENANT', '0');
} catch (error) {
console.log('handleLogout Error', error);
}
};
|
@jeromeheissler and @imdkbj I noticed you are both calling |
Same thing.
try {
await handleLogout();
// await DataStore?.stop?.();
await DataStore?.clear?.();
} catch (error) {
console.log('Hub signOut error', error);
} |
Yes, Its, continued, not working |
We have a temporary solution for Datastore clear and Datastore stop, But why we can't use "aws-amplify"@latest |
@santhoshpriya0715 and @jeromeheissler can either of you confirm that you're using the SQLite adapter, similar to @imdkbj ? |
yes, exactly what @imdkbj used. |
I'm not using it. |
Work Around (TLDR)Add the polyfill to your dependencies.
Then add the following to somewhere near the root of your app (such as import allSettled from 'promise.allsettled';
allSettled.shim(); ExplanationThe issue is that the polyfill for The workaround suggested in facebook/hermes#766 (comment) will unblock current versions of React Native. The workaround is clearly not a great experience, so we will be looking into a proper fix. |
As you said we tried allSettled.shim(), Datastore.clear() and Datastore.stop() in aws-amplify@4.3.42 worked. Though it worked in aws-amplify@4.3.42, it has relationship link issue once datastore is cleared & stopped and started again. |
Looks like Hermes is also missing The polyfill from core-js should solve this.
Then add this as the top of the imports for your app.
|
Symbol.asyncIterator issue cleared, But below issue not solved yet. WARN Possible Unhandled Promise Rejection (id: 0):Object { |
@santhoshpriya0715, I am unable to reproduce this error. Can you open a new issue with the minimum reproduction? |
I was having the same error when using this import |
Hi @santhoshpriya0715 👋 can you confirm if the comment by @ervibern serves as a workaround for you? It's odd that importing the named DataStore package from Let me know if any of that helps. |
We will not be adding polyfills directly to the Amplify library. React Native v0.71.0 with Hermes now includes the necessary polyfills. The recommended course of action is to either:
|
I have added polyfill but still getting the same, tried each things named export/core-js/updated amplify etc... Lastly, I have to remove stop && clear to get it working. |
Can you share the Amplify version and React Native version you are using? |
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
DataStore
Amplify Categories
Not applicable
Environment information
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 {
};
Log output
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
The text was updated successfully, but these errors were encountered: