Skip to content

fix(expo): prevent crash when importing @clerk/expo in web environments#8066

Open
chriscanin wants to merge 3 commits intomainfrom
chris/fix-expo-web-crash
Open

fix(expo): prevent crash when importing @clerk/expo in web environments#8066
chriscanin wants to merge 3 commits intomainfrom
chris/fix-expo-web-crash

Conversation

@chriscanin
Copy link
Member

@chriscanin chriscanin commented Mar 13, 2026

Summary

  • Fixes @clerk/expo crashing with Cannot read properties of undefined (reading 'get') when used in Expo web environments
  • The crash occurs because TurboModuleRegistry from react-native is undefined on web (react-native-web), and NativeClerkModule.ts calls TurboModuleRegistry.get('ClerkExpo') at module evaluation time — before any runtime guards can protect against it
  • Adds .web.ts variants for NativeClerkModule (exports null) and polyfills (empty — browsers have native URL and base64), following the existing pattern used by singleton.web.ts

Error: Uncaught Error: Cannot read properties of undefined (reading 'get') at NativeClerkModule.js

Test plan

  • Verify @clerk/expo no longer crashes when bundled for web (Expo web / react-native-web)
  • Verify native (iOS/Android) functionality is unaffected — TurboModuleRegistry.get() still runs on native via the original .ts file
  • Verify hooks (useSignIn, useSSO, useAuth) work correctly on web

Summary by CodeRabbit

  • Bug Fixes
    • Fixed web crashes in the Expo package by improving native module import handling and providing proper fallback behavior when modules are unavailable on web platforms.

Add .web.ts variants for NativeClerkModule spec and polyfills so the
bundler skips TurboModuleRegistry and react-native-url-polyfill on web.
@vercel
Copy link

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Mar 13, 2026 4:13pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2026

🦋 Changeset detected

Latest commit: a4f23d2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clerk/expo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8bcbe78d-4d4b-443b-ad66-6d66d6a0400d

📥 Commits

Reviewing files that changed from the base of the PR and between 18ccf31 and 0c88601.

📒 Files selected for processing (1)
  • packages/expo/src/specs/NativeClerkModule.ts

📝 Walkthrough

Walkthrough

A patch is being introduced to address web crashes in the Clerk Expo package. The changes include adding a new changelog entry documenting the fix, creating a new web-specific polyfills file that indicates no polyfills are required in web environments, and modifying the NativeClerkModule to use optional chaining and nullish coalescing when accessing the TurboModuleRegistry, allowing it to return null when the registry is unavailable rather than throwing an error.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main fix: preventing crashes when importing @clerk/expo in web environments, which is the core objective of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Replace .web.ts approach with optional chaining in the original spec
file. This avoids TypeScript build issues from moduleSuffixes while
still preventing the crash when TurboModuleRegistry is undefined on web.
@chriscanin
Copy link
Member Author

chriscanin commented Mar 13, 2026

Screenshot 2026-03-13 at 9 07 32 AM Screenshot 2026-03-13 at 9 10 34 AM

I was able to reproduce Yu's error, and this is a screenshot of before and after from this fix.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 13, 2026

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@8066

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8066

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8066

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8066

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8066

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@8066

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8066

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8066

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8066

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8066

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8066

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8066

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8066

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8066

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8066

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8066

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8066

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8066

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8066

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8066

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8066

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8066

commit: a4f23d2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant