[expo-router] Typed routes: getWatchHandler admits files outside the app root on Windows, poisoning router.d.ts
Minimal reproducible example
No repository — this is a source-level defect in @expo/router-server, reproducible in five lines
of standalone Node (below) and readable directly at
packages/@expo/router-server/src/typed-routes/index.ts#L33-L37
on main as of today. I am happy to build a repro app if that is still wanted, but the bug needs a
Windows host and a monorepo to show itself, which makes a repository a poor carrier for it.
Steps to reproduce
getWatchHandler decides whether a changed file belongs to the app root by testing a
path.relative() result against the POSIX-only prefix '../':
let relativePath = path.relative(process.env.EXPO_ROUTER_APP_ROOT, filePath);
const isInsideAppRoot = !relativePath.startsWith('../');
// ...
if (!isInsideAppRoot) return;On Windows path.relative() returns backslash separators, so the check never matches and every
file outside the app root is accepted as a route. Metro watches the workspace root in a monorepo,
so with expo start running, editing any .ts file anywhere in the repo writes garbage into
.expo/types/router.d.ts.
Standalone reproduction (Windows, Node 22):
import path from 'node:path';
const APP_ROOT = String.raw`C:\repo\apps\expo\src\app`;
const changed = String.raw`C:\repo\packages\api\src\seed.ts`;
const rel = path.relative(APP_ROOT, changed); // '..\\..\\..\\..\\packages\\api\\src\\seed.ts'
console.log(!rel.startsWith('../')); // true — accepted, should be rejectedEnd to end, in a pnpm workspace whose app root is apps/expo/src/app:
- Run
npx expo starton Windows. - Touch any
.tsfile in a sibling package, e.g.packages/api/src/seed.ts. apps/expo/.expo/types/router.d.tsgains union members such as:
href: /* … */ | `/../../../../packages/api/src/seed${`?${string}` | `#${string}` | ''}`;Expected: files outside EXPO_ROUTER_APP_ROOT are ignored, and the declaration keeps only real
routes.
Actual: every real route then fails to typecheck against that union:
src/app/login.tsx(222,40): error TS2345: Argument of type '"/kiosk"' is not assignable to
parameter of type 'RelativePathString | ExternalPathString |
"/../../../../packages/api/src/seed" | ...'I hit 19 such errors across an app of 11 routes.
Platform: Windows only (Linux and macOS path.relative() yield ../, so the check works).
Environment: expo start in a pnpm monorepo, development build.
Three things make it unusually costly to diagnose:
.expo/is gitignored, so the poisoned file is invisible to review and to a fresh clone.- CI on Linux stays green, so it looks like a machine-specific type regression in the app.
- The initial
regenerateDeclarationsis scoped correctly byrequireContext(EXPO_ROUTER_APP_ROOT), so the file starts out right and only degrades later — the symptom appears long after any change that could explain it.
Suggested fix
Compare the first path segment rather than a hard-coded POSIX prefix:
const isInsideAppRoot = relativePath.split(path.sep)[0] !== '..';@expo/cli already gets this right elsewhere — getTypedRoutesUtils.isRouteFile in
packages/@expo/cli/src/start/server/type-generation/routes.ts uses relative.startsWith('..'),
which is separator-agnostic — but the watch path does not go through it. Reusing it would fix this
and remove the duplicated rule.
Related but distinct: #33146 fixed a different Windows separator problem in the same file (route key normalization), not this containment check.
Environment
expo-env-info 2.1.0 environment info:
System:
OS: Windows 11 10.0.26200
Binaries:
Node: 22.21.0
npm: 10.9.4
npmPackages:
expo: ~57.0.14 => 57.0.14
expo-router: ~57.0.14 => 57.0.14
react: 19.2.3
react-dom: 19.2.3
react-native: ~0.86.2 => 0.86.2
Expo Workflow: managed
Resolved transitively: @expo/cli 57.0.16, @expo/router-server 57.0.6
Package manager: pnpm 10.19.0 workspace; app root at apps/expo/src/appExpo Doctor Diagnostics
Patch version mismatches
package expected found
expo ~57.0.18 57.0.14
expo-constants ~57.0.16 57.0.12
expo-dev-client ~57.0.16 57.0.13
expo-linking ~57.0.8 57.0.6
expo-router ~57.0.17 57.0.14
expo-secure-store ~57.0.2 57.0.1
expo-splash-screen ~57.0.8 57.0.7
expo-system-ui ~57.0.3 57.0.2
react-native 0.86.3 0.86.2
react-native-reanimated 4.5.1 4.5.3
react-native-worklets 0.10.1 0.10.4
jest-expo ~57.0.5 57.0.4
13 packages out of date.These are patch-version drifts in my app and are not the cause: the defect is present verbatim in
the source on main today, at the permalink above, so no dependency upgrade clears it.
Source: expo/expo