Skip to content

sentry wizard reactNative never adds Sentry.init: the App file lookup finds nothing #7149

Done
getsentry/toolkit
#2604

Description

@antonis

sentry wizard reactNative (toolkit main) doesn't find the app's entry file on a fresh bare React Native app or a fresh Expo app. So it never adds Sentry.init or Sentry.wrap. It prints "Could not find main App file", shows both snippets to paste by hand, and then still ends with "Everything is set up!". Found while testing the port for RN-871.

Two causes

  1. A regression from the port. getMainAppFilePath() in packages/cli/src/lib/wizard/react-native/javascript.ts uses the upstream pattern {.,./src,./app}/+(@(App|_layout).@(j|t|cj|mj)s?(x)). The port replaced glob with tinyglobby (toolkit#2511), and under tinyglobby this pattern matches nothing, even a root App.tsx. Upstream with glob found it.
  2. A gap that predates the port. The Expo SDK 58 template puts the layout at src/app/_layout.tsx. The pattern only covers ., ./src and ./app, so this path isn't found even upstream.

The unit test (test/lib/wizard/react-native/add-sentry-init.test.ts) mocks getFirstMatchedPath, so the pattern itself was never exercised.

Repro

  • Bare RN: npx @react-native-community/cli init WizRn --version 0.88.1, then sentry wizard <org>/<project> reactNative → "Could not find main App file". App.tsx is at the root.
  • Expo: npx create-expo-app WizExpo (SDK 58), then the same → "Could not find main App file". The layout is src/app/_layout.tsx.

Suggested fix

Search the candidate directories in order, with plain braces that tinyglobby supports, and add src/app:

// packages/cli/src/lib/wizard/react-native/javascript.ts
const APP_FILE_NAMES = "{App,_layout}.{js,jsx,ts,tsx,cjs,mjs}";
/** Checked in order: the first directory with a match wins. */
const APP_FILE_DIRS = [".", "src", "app", "src/app"];

export function getMainAppFilePath(): string | undefined {
  return traceStep("find-app-js-file", () => {
    for (const dir of APP_FILE_DIRS) {
      const pattern = dir === "." ? APP_FILE_NAMES : `${dir}/${APP_FILE_NAMES}`;
      const match = getFirstMatchedPath(pattern);
      if (match) {
        return match;
      }
    }
    return undefined;
  });
}

Checked with tinyglobby (the CLI's version), using the same ignore list as getFirstMatchedPath:

Layout Match
Bare RN 0.88 template App.tsx
Expo SDK 58 template src/app/_layout.tsx
app/_layout.tsx (older Expo Router) ✅
src/App.js ✅
App.jsx ✅
src/app/_layout.js ✅
Only node_modules/x/App.js or lib/App.js none (correct)

Notes:

  • The order keeps upstream's priority (root, src, app), with src/app added last. Looping per directory makes the order deterministic, which a single glob's result order isn't.
  • Upstream's extension set also allowed cjsx/mjsx, which aren't real React Native entry files, so they're dropped.
  • Add a test against the real filesystem, not the mocked glob helper. Use a temporary directory per layout above, and process.chdir into it, since getFirstMatchedPath globs relative to the working directory. Exporting getMainAppFilePath makes that easy.

Done when

  • The fix is in toolkit (PR referencing this issue), with a real-filesystem test for the layouts above.
  • sentry wizard reactNative adds Sentry.init and Sentry.wrap on a fresh bare RN app and a fresh Expo SDK 58 app.

Activity

  1. self-assigned this
    on Nov 30, 2026
  2. linear-code commented on Nov 30, 2026

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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions