You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用<ClerkProvider>包裹App.js后Android打包失败问题求助

问题

使用<ClerkProvider>包裹App.js后,重新加载React Native Expo项目时出现以下错误:

  • Android Bundling failed 589ms C:\My Work\React Native\First\node_modules\expo\AppEntry.js (1 module)
  • 无法解析 "@clerk/shared" 模块,路径为 "node_modules@clerk\clerk-react\dist\index.js"

App.js 代码

import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import Login from './Apps/Screens/LoginScreen/Login';
import { ClerkProvider,SignedIn, SignedOut  } from "@clerk/clerk-expo";


export default function App() {
  return (
    <ClerkProvider publishableKey={'pk_test_ZGFzaGluZy1maXNoLTc0LmNsZXJrLmFjY291bnRzLmRldiQ'}>
      <View style={styles.container}>
          <SignedIn>
              <Text>You are Signed in</Text>
          </SignedIn>
          <SignedOut>
              <Login/>
          </SignedOut>
          <StatusBar style="auto" />
      </View>
    </ClerkProvider>
  );
}

package.json 代码

{
  "name": "first",
  "version": "1.0.0",
  "main": "expo/AppEntry.js",
  "scripts": {
    "start": "expo start --tunnel",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@clerk/clerk-expo": "^1.1.4",
    "expo": "~51.0.8",
    "expo-status-bar": "~1.12.1",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "react-native": "0.74.1"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}
解决方案

针对无法解析@clerk/shared的问题,可尝试以下步骤:

  1. 清理缓存并重新安装依赖

    • 执行命令清除npm缓存:npm cache clean --force
    • 删除项目根目录下的node_modules文件夹和package-lock.json文件
    • 重新安装所有依赖:npm install
  2. 升级@clerk/clerk-expo到兼容版本
    当前使用的@clerk/clerk-expo@1.1.4可能与Expo 51存在兼容性问题,尝试升级到最新版本:

    npm install @clerk/clerk-expo@latest
    
  3. 手动安装缺失的依赖
    直接安装@clerk/shared模块,补充缺失的依赖项:

    npm install @clerk/shared
    

完成上述操作后,重新启动Expo项目,检查错误是否解决。

内容的提问来源于stack exchange,提问作者Soufiane Fathaoui

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 02:33:26