Repository navigation
Done
getsentry/toolkit
#2604Labels
Description
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
- A regression from the port.
getMainAppFilePath()inpackages/cli/src/lib/wizard/react-native/javascript.tsuses the upstream pattern{.,./src,./app}/+(@(App|_layout).@(j|t|cj|mj)s?(x)). The port replacedglobwithtinyglobby(toolkit#2511), and undertinyglobbythis pattern matches nothing, even a rootApp.tsx. Upstream withglobfound it. - A gap that predates the port. The Expo SDK 58 template puts the layout at
src/app/_layout.tsx. The pattern only covers.,./srcand./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, thensentry wizard <org>/<project> reactNative→ "Could not find main App file".App.tsxis at the root. - Expo:
npx create-expo-app WizExpo(SDK 58), then the same → "Could not find main App file". The layout issrc/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), withsrc/appadded 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.chdirinto it, sincegetFirstMatchedPathglobs relative to the working directory. ExportinggetMainAppFilePathmakes that easy.
Done when
- The fix is in toolkit (PR referencing this issue), with a real-filesystem test for the layouts above.
-
sentry wizard reactNativeaddsSentry.initandSentry.wrapon a fresh bare RN app and a fresh Expo SDK 58 app.
Activity
linear-code commentedon Nov 30, 2026
RN-904