amplify-js: DataStore - subscriptionError Connection failed: NetInfo must be passed to networkMonitor to enable reachability in React Native

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

DataStore

Amplify Categories

api

Environment information

# Put output below this line
  System:
    OS: macOS 12.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 2.25 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.7.0 - /opt/homebrew/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.15.0 - /opt/homebrew/bin/npm
    Watchman: 2022.07.04.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 103.0.5060.134
    Safari: 15.6
  npmGlobalPackages:
    npm: 8.15.0
    yarn: 1.22.17

Describe the bug

Since aws-amplify@4.3.30 DataStore Subscriptions are not working anymore.

DataStore - subscriptionError Connection failed: NetInfo must be passed to networkMonitor to enable reachability in React Native please see Reproduction steps and Log output below.

Even downgrading (strictly) to aws-amplify@4.3.27 won’t help as npm/yarn will start installing false dependencies.

Expected behavior

DataStore Subscriptions should work as documented.

Reproduction steps

  1. Follow Amplify Getting Started with React Native Guide
  2. Start the React Native app and see the errors popping up in the terminal

Code Snippet

This is the regular way to invoke subscriptions, causing the errors shown in the log below.

  useEffect(() => {

    //query the initial todolist and subscribe to data updates
    const subscription = DataStore.observeQuery(Todo).subscribe((snapshot) => {
      //isSynced can be used to show a loading spinner when the list is being loaded. 
      const { items, isSynced } = snapshot;
      setTodos(items);
    });

    //unsubscribe to data updates when component is destroyed so that we don’t introduce a memory leak.
    return function cleanup() {
      subscription.unsubscribe();
    }

  }, []);

Log output

 WARN  [WARN] 18:14.460 DataStore - subscriptionError Connection failed: NetInfo must be passed to networkMonitor to enable reachability in React Native
 WARN  [WARN] 18:14.461 DataStore {"cause": {"error": {"errors": [Array]}, "provider": {"_config": [Object], "connectionStateMonitor": [ConnectionStateMonitor], "keepAliveTimeout": 300000, "promiseArray": [Array], "socketStatus": 0, "subscriptionObserverMap": [Map]}}, "errorType": "Unknown", "localModel": null, "message": "Connection failed: NetInfo must be passed to networkMonitor to enable reachability in React Native", "model": "Todo", "operation": "Create", "process": "subscribe", "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null}

 WARN  [WARN] 18:14.462 DataStore - subscriptionError Connection failed: NetInfo must be passed to networkMonitor to enable reachability in React Native
 WARN  [WARN] 18:14.462 DataStore {"cause": {"error": {"errors": [Array]}, "provider": {"_config": [Object], "connectionStateMonitor": [ConnectionStateMonitor], "keepAliveTimeout": 300000, "promiseArray": [Array], "socketStatus": 0, "subscriptionObserverMap": [Map]}}, "errorType": "Unknown", "localModel": null, "message": "Connection failed: NetInfo must be passed to networkMonitor to enable reachability in React Native", "model": "Todo", "operation": "Update", "process": "subscribe", "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null}

 WARN  [WARN] 18:14.462 DataStore - subscriptionError Connection failed: NetInfo must be passed to networkMonitor to enable reachability in React Native
 WARN  [WARN] 18:14.462 DataStore {"cause": {"error": {"errors": [Array]}, "provider": {"_config": [Object], "connectionStateMonitor": [ConnectionStateMonitor], "keepAliveTimeout": 300000, "promiseArray": [Array], "socketStatus": 0, "subscriptionObserverMap": [Map]}}, "errorType": "Unknown", "localModel": null, "message": "Connection failed: NetInfo must be passed to networkMonitor to enable reachability in React Native", "model": "Todo", "operation": "Delete", "process": "subscribe", "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null}

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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 14
  • Comments: 17 (4 by maintainers)

Most upvoted comments

I manually downgraded to 4.3.24 (using the exact version without ~ or ^) using yarn for the time being. Hoping for a reaction by an AWS official developer.

A fix was released yesterday. Can you confirm that it works with the latest version of amplify?

We’re facing the same issue. Thanks for opening this issue, it would have taken us at least some more hours to realize that this is an issue with the amplify version. Downgrading aws-amplify with a pnpm override to 4.3.27 is a workaround for us at the moment and perhaps it helps other pnpm users who stumble over this.


"dependencies": {
...
    "aws-amplify": "4.3.27",
    "@react-native-community/netinfo": "8.3.1",
    "aws-amplify-react-native": "^6.0.5",
...
},
"pnpm": {
  "overrides": {
    "aws-amplify": "4.3.27",
    "@react-native-community/netinfo": "8.3.1"
  }
}

WARN [WARN] 23:05.947 DataStore - subscriptionError Connection failed: {“errors”:[{“message”:“Validation error of type FieldUndefined: Field ‘_version’ in type ‘Dish’ is undefined @ ‘onUpdateDish/_version’”},{“message”:“Validation error of type FieldUndefined: Field ‘_lastChangedAt’ in type ‘Dish’ is undefined @ ‘onUpdateDish/_lastChangedAt’”},{“message”:“Validation error of type FieldUndefined: Field ‘_deleted’ in type ‘Dish’ is undefined @ ‘onUpdateDish/_deleted’”}]} WARN [WARN] 23:05.964 DataStore {“cause”: {“error”: {“errors”: [Array]}, “provider”: {“_config”: [Object], “awsRealTimeSocket”: [WebSocket], “connectionState”: “Connecting”, “connectionStateMonitor”: [ConnectionStateMonitor], “connectionStateMonitorSubscription”: [Subscription], “keepAliveAlertTimeoutId”: 513, “keepAliveTimeout”: 300000, “keepAliveTimeoutId”: 512, “promiseArray”: [Array], “reconnectionMonitor”: [ReconnectionMonitor], “socketStatus”: 1, “subscriptionObserverMap”: [Map]}}, “errorType”: “Unknown”, “localModel”: null, “message”: “Connection failed: {"errors":[{"message":"Validation error of type FieldUndefined: Field ‘_version’ in type ‘Dish’ is undefined @ ‘onUpdateDish/_version’"},{"message":"Validation error of type FieldUndefined: Field ‘_lastChangedAt’ in type ‘Dish’ is undefined @ ‘onUpdateDish/_lastChangedAt’"},{"message":"Validation error of type FieldUndefined: Field ‘_deleted’ in type ‘Dish’ is undefined @ ‘onUpdateDish/_deleted’"}]}”, “model”: “Dish”, “operation”: “Update”, “process”: “subscribe”, “recoverySuggestion”: “Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues”, “remoteModel”: null}

i can read data from aws amplify any one help please

@undefobj Looks like thats what it was!! I’m sure i set the token duration for 10years (3649 days), but it looks like it needs refreshing often. Is there any way i can set this for sure for a multiple year duration?