Skip to content

Native module not found in React Native when subscribe to graphql with @aws-amplify/api #14389

Open
@duyta7598

Description

@duyta7598

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

GraphQL API

Amplify Version

v6

Amplify Categories

api

Backend

None

Environment information

# Put output below this line


Describe the bug

Hi team,

I am encountering an issue when trying to use GraphQL subscriptions in a React Native project with the @aws-amplify/api package (version 6.x).

Problem details:
• Query and mutation operations work correctly using the generateClient method.
• However, when attempting to subscribe to a GraphQL subscription, I get the following runtime error:
error subscribe [Error: Native module not found] [Component Stack]

•	This error appears to be related to missing native WebSocket modules required for subscription support.
•	I am using Expo bare workflow, and have confirmed that the environment supports native modules.
•	The subscription setup follows the Amplify docs but still fails.

Questions:
1. Is subscription currently fully supported with generateClient in React Native / Expo?
2. If yes, what is the recommended setup or workaround to fix the “Native module not found” error?
3. Are there plans to fix or provide better React Native subscription support in @aws-amplify/api v6?

I would appreciate any guidance or fixes to properly enable subscriptions with Amplify in React Native.

Thank you!

Expected behavior

Subscriptions should connect and receive real-time updates as intended.

Reproduction steps

  1. Create a React Native project using Expo bare workflow.
  2. Install @aws-amplify/api version 6 and related Amplify dependencies.
  3. Configure Amplify with a valid AppSync GraphQL API using generateClient with authMode: "apiKey".
  4. Implement query and mutation calls using the generated client — these should work fine.
  5. Implement a GraphQL subscription using the same client’s .graphql({ query }).subscribe() method.
  6. Run the app on a physical device or emulator.
  7. Observe the runtime error: Error: Native module not found when starting the subscription.

Code Snippet

// Put your code below this line.
const useGraphQLSubscription = <
  TSubscriptionVariables = any,
  TSubscriptionResponse = any,
>({
  query,
  variables,
  callback,
  enabled = true,
}: Props<TSubscriptionVariables, TSubscriptionResponse>) => {
  useEffect(() => {
    if (!enabled) return;
    const subscription = graphQLClient
      .graphql({
        query,
        variables: variables || ({} as any),
      })
      .subscribe({
        next: ({ data }) => {
          callback(data as TSubscriptionResponse);
        },
        error: (error) => console.warn("error subscribe", error),
      });

    return () => {
      subscription.unsubscribe();
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [callback, variables, enabled]);
};

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    GraphQLRelated to GraphQL API issuesReact NativeReact Native related issuepending-maintainer-responseIssue is pending a response from the Amplify team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions