@google-cloud/recaptcha-enterprise-react-native

中文文档
18.9.4发布于 2026/11/07ApacheTypeScriptESM + CJS零依赖近 30 天下载 31.9万

React Native plugin for reCAPTCHA Enterprise Mobile SDK

原始使用文档
文档目录12 节
  1. Setup
  2. Podfile
  3. Basic Usage
  4. 1. Import Recaptcha
  5. 2. Initialize the client
  6. 3. Fetch Token
  7. Example App
  8. Common Problems:
  9. error: include of non-modular header inside framework modul…
  10. `fatal error: 'FlipperKit/FlipperClient.h' file not found #…
  11. SDK Location Not found
  12. Unsupported class file major version 67

reCAPTCHA Enterprise React Native Module

Please note that issues filed in this repository are not an official Google support channel and are answered on a best effort basis. For official support, please visit: https://cloud.google.com/support-hub.

If you have an issue with the React Native plugin please post issues in this repository. If you are having issues with the underlying SDK, please post issues in https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk.

For general documentation on reCAPTCHA Enterprise for mobile applications, see Android and iOS.

Setup

[!IMPORTANT] Version 18.9.4 and later require React Native >=0.87.0.

Add the package to your React Native project:

npx yarn add @google-cloud/recaptcha-enterprise-react-native

If using VSCode install eslint:

https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint

You may need to use an older JDK:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home

Podfile

Similar to Firebase, the library requires frameworks and static linkage:

use_frameworks! :linkage => :static

And flipper is not compatible with static linkage so disable flipper in the Podfile:

flipper_config = FlipperConfiguration.disabled

Swift Package Manager (SPM)

By default, the iOS native SDK (RecaptchaEnterprise) is installed via CocoaPods. On React Native versions that support spm_dependency (React Native 0.75+), you can opt in to resolving the native RecaptchaEnterprise iOS SDK via Swift Package Manager instead by setting USE_SPM=1 (or RECAPTCHA_USE_SPM=1) when running pod install:

USE_SPM=1 pod install

Or by setting ENV['RECAPTCHA_USE_SPM'] = '1' at the top of your ios/Podfile.

Basic Usage

This section shows how to integrate with reCAPTCHA SDK.

1. Import Recaptcha

Use the following imports to access the APIs provided by the SDK.

import {
  Recaptcha,
  RecaptchaAction,
  type RecaptchaClient,
} from '@google-cloud/recaptcha-enterprise-react-native';

2. Initialize the client

Instantiate a client by using the reCAPTCHA key (KEY_ID) that you created for your Android/iOS app.

const client = await Recaptcha.fetchClient(SITE_KEY);

[!NOTE] You must initialize the reCAPTCHA client only once during the lifetime of your app.

3. Fetch Token

For each action of your app that is protected using reCAPTCHA, call the execute method passing a RecaptchaAction. reCAPTCHA provides a built-in set of actions and if necessary you can create custom actions.

The following code snippet shows how to use execute to protect a LOGIN action.

const token = await client.execute(RecaptchaAction.LOGIN());

In case a custom action use RecaptchaAction.custom('ACTION');

Example App

Follow guidance at Example App.

Common Problems:

error: include of non-modular header inside framework module 'RecaptchaEnterprise.Recaptcha'

Use static linking in pods, for instance: USE_FRAMEWORKS=static pod install or use_frameworks! :linkage => :static in your Podfile.

`fatal error: 'FlipperKit/FlipperClient.h' file not found #import

<FlipperKit/FlipperClient.h>`

Flipper is not yet compatible with static linkage, so disable flipper in your Podfile: flipper_config = FlipperConfiguration.disabled

SDK Location Not found

Run the following command in the terminal:

export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk

Unsupported class file major version 67

This happens when a unsupported Java version is used. Run

npx react-native doctor

To discover the version that's being used and the supported ones. Change the version of Java to a supported one and try again.

版本与发布记录

@google-cloud/recaptcha-enterprise-react-native 共发布 23 个版本,首次发布于 2023/06/16;过去 12 个月发布了 7 个版本。

版本发布日期距今
18.9.4latest2026/11/0710 天前
18.9.32026/10/2721 天前
18.9.22026/07/164 个月前
18.9.12026/06/244 个月前
18.9.02026/06/244 个月前
18.9.0-beta012026/02/059 个月前

其他发布通道:beta → 18.8.0-beta02。

关于 @google-cloud/recaptcha-enterprise-react-native 的常见问题

@google-cloud/recaptcha-enterprise-react-native 是什么?

React Native plugin for reCAPTCHA Enterprise Mobile SDK

如何安装 @google-cloud/recaptcha-enterprise-react-native?

在项目目录运行 npm install @google-cloud/recaptcha-enterprise-react-native,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(>=0.87.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@google-cloud/recaptcha-enterprise-react-native 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@google-cloud/recaptcha-enterprise-react-native 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@google-cloud/recaptcha-enterprise-react-native 可以商用吗?

@google-cloud/recaptcha-enterprise-react-native 使用 Apache 许可。声明的许可为 Apache,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@google-cloud/recaptcha-enterprise-react-native 的下载量有多少?

根据 npm 官方下载统计,@google-cloud/recaptcha-enterprise-react-native 在 2026/10/17 – 2026/11/15 这 30 天内被下载 318,661 次,日均约 10,622 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@google-cloud/recaptcha-enterprise-react-native 还在维护吗?

最新版本 18.9.4 发布于 2026/11/07(10 天前);至今共发布 23 个版本,其中过去 12 个月发布了 7 个;首次发布于 2023/06/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。