Skip to content

fix: react native support - #6

Closed
rexxars wants to merge 5 commits into
sxzz:mainfrom
rexxars:fix/react-native
Closed

rexxars wants to merge 5 commits into
sxzz:mainfrom
rexxars:fix/react-native

Conversation

@rexxars

@rexxars rexxars commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

AI usage

  • No AI was used in this PR.
  • AI was used:
    • I have carefully reviewed the AI-generated content myself.

Description

React Native/Expo projects with the metro bundler module resolution resolves obug to it's default export field, which it has pointed to the node target, which is using node-specific imports (node:tty) and crashes.

I'd argue the more logical stance is to default to a "runtime agnostic" build - currently the closest to that is the browser build, although you could argue a third build that doesn't use CSS/hex colors etc might be a more logical fallback. This PR swaps the default to be the browser build for now. Deno and Bun also uses it, so they resolve to same build as before.

Additionally, react native/expo doesn't support the %c formatting so it would print things like %cobug:app %chello %c+0ms unless a chrome debugger is attached. Not quite sure what the best solution is here - currently I feature-checked on document, but that might also exclude workers, so open to other suggestions - but was worried about adding too many bytes to the bundle here.

Linked Issues

None

Additional context

The colors check is up for debate - very open to changing or dropping that commit, the most important thing is preventing this from crashing when used in react native.

Comment thread src/browser.ts Resolved
Comment thread package.json
".": {
"browser": "./dist/browser.js",
"default": "./dist/node.js"
"node": "./dist/node.js",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please test on other runtimes, like Bun, Deno, workerd, and check if they work well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added test scripts for deno and bun to package.json and ran these locally - they all pass. I didn't know how far you wanted me to take this: do you want github workflows that run the smoke tests on bun and deno as well? Do you want to run the entire test suite on the different runtimes? Am I okay to add dependencies like cloudflare workers pool for vitest?

In this fork, we took it all the way (since we use obug inside of @sanity/client, which needs to run on all these different runtimes) - but again; not sure how much infrastructure/changes you're willing to deal with?

Comment thread tests/exports.test.ts Resolved
@rexxars
rexxars requested a review from sxzz September 1, 2026 21:25
@sxzz sxzz closed this in 23cf7f7 Sep 9, 2026
sxzz added a commit that referenced this pull request Sep 9, 2026
Co-authored-by: Espen Hovlandsdal <[email protected]>
closes #1, closes #6
@sxzz

sxzz commented Sep 9, 2026

Copy link
Copy Markdown
Owner

Thanks for your contribution! I added you to 0e828cd commit

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants