Skip to content

Fix the package name and unblock running the RN example against a linked SDK - #42

Merged
yosriady merged 1 commit into
mainfrom
fix/react-native-example-linked-sdk
Jul 31, 2026
Merged

Fix the package name and unblock running the RN example against a linked SDK#42
yosriady merged 1 commit into
mainfrom
fix/react-native-example-linked-sdk

Conversation

@yosriady

@yosriady yosriady commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Three separate things stopped with-react-native from building or testing against a local checkout of the SDK. Found while verifying getformo/sdk-react-native#69 and #70.

1. Transposed package name broke the whole test suite

jest.setup.js mocked @formo/react-native-analytics; the package is @formo/analytics-react-native. The mock matched nothing, so both suites failed to run — 0 tests. Now 11 pass.

The README carried the same transposed name in its install snippet and every import example, which is almost certainly where the typo came from. Fixed there too.

2. Metro could not resolve a linked SDK

Metro honours the package exports map, which points at lib/commonjs/index.js — but sdk-react-native/.watchmanconfig lists "lib" in ignore_dirs, so Metro's crawler never sees that file. Resolution fails with "none of these files exist" even when the build output is present, which makes it a confusing thing to debug. exports also takes precedence over the react-native field that would otherwise have pointed at src.

Resolved by pinning the package to its TypeScript source. That is what the rest of this resolver already assumes — the redirect immediately below keys on originModulePath being inside sdkPath, which only happens when the SDK is consumed as source. It also means SDK edits hot reload with no rebuild, which is the point of linking.

Verification

expo start --web bundles (2827 modules, HTTP 200), the SDK reports Initialized, and screen / track / lifecycle events reach events.formo.so/v0/raw_events. Confirmed in Tinybird: page events with page_url: app://Home / app://Wallet / app://Events, plus Application Installed, Application Opened and Deep Link Opened in spec order.

Running it this way is also what surfaced a real bug in the Tinybird pipe (getformo/formono#2033): Expo web reports os_name: "Mac OS" when expo-device is installed, not "web", so a Mac browser session was classifying as an iPhone.

Not included

The link: entry in package.json is intentionally not committed — it holds an absolute path. To run against a local SDK:

pnpm add "@formo/analytics-react-native@link:../../sdk-react-native"

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Three things stopped this example from building or testing against a local
checkout of the SDK:

- jest.setup.js mocked "@formo/react-native-analytics" — the package is
  "@formo/analytics-react-native". The mock therefore matched nothing and
  both suites failed to run: 0 tests. Now 11 pass.
- The README had the same transposed name in its install snippet and import
  examples, which is almost certainly where the typo came from.
- Metro could not resolve the SDK when linked. It honours the package
  `exports` map, which points at lib/commonjs/index.js, but
  sdk-react-native/.watchmanconfig lists "lib" in ignore_dirs — so Metro's
  crawler never sees that file and resolution fails with "none of these files
  exist" even when the build output is present. `exports` also takes
  precedence over the `react-native` field that would have avoided this.

  Resolved by pinning the package to its TypeScript source, which is what the
  rest of this resolver already assumes: the redirect below it keys on
  originModulePath being inside sdkPath, which only happens when the SDK is
  consumed as source. It also means SDK edits hot reload with no rebuild.

Verified end to end: `expo start --web` now bundles (2827 modules, HTTP 200),
the SDK initialises, and screen/track/lifecycle events reach the ingest API.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@yosriady
yosriady merged commit 93af4d3 into main Jul 31, 2026
7 checks passed
yosriady added a commit that referenced this pull request Aug 2, 2026
Metro resolver: the redirect added in #42 fired unconditionally, so the
package resolved to ../../sdk-react-native/src for ANYONE with a sibling
checkout — silently running unreleased local code instead of the pinned
version — and resolved to a non-existent path for anyone without one. Caught
while verifying the example against the published SDK: it kept reporting
unreleased behaviour. Now gated on the node_modules entry actually being a
symlink, which is exactly what distinguishes `pnpm add link:` from an install.
Verified both ways round: npm install emits app://Wallet (1.0.0), a link emits
app://com.formo.analytics.demo/Wallet.

Dependency: ^0.1.6 -> ^1.0.0. The caret meant 0.1.6 could never pick up 1.x,
so the example was two majors behind.

App identity now comes from app.json via expo-constants instead of a hardcoded
copy. config/formo.ts claimed version 1.1.0 while app.json said 1.0.0 — and
these reach Formo as `app_version` and as the mobile `origin`, so the drift
meant every event reported a version the app never had. The test asserted the
literal 1.1.0, which is how it went unnoticed; it now asserts the two agree.

Kept the explicit app config rather than relying on auto-detection: in Expo Go
the native modules report EXPO GO's bundle id and version, and on React Native
Web nothing resolves a bundle id at all.

README: screen() takes (name, category?, properties?) — the example passed an
object where the category string goes, which would have sent [object Object].

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant