Skip to content

Ecosystem detection misses React Native libraries that don't declare react-native, and their closure #763

Open

Description

@danfry1

Summary

A React Native library whose manifest doesn't declare react-native (in dependencies or peerDependencies) isn't detected by the native engine's ecosystem auto-inline, and neither is anything in its dependency closure. Projects have to keep transform: [...] lists by hand for it.

Status

  • Done in fix(native): compile JSX in a package's .js file that Vite serves uncompiled #767 (0.15.1): JSX in such a package's .js file no longer fails Vite's import analysis. A file Vite's parser rejects is compiled as JSX at load and stays in Vite; files that parse are untouched.
  • Left for 0.16: the two parts below. react-native-calendars@1.1314.0 still needs reactNative({ transform: ['react-native-calendars'] }). Without it, the run now stops at an error that names the package and that fix.

Remaining 1: detect undeclared React Native libraries

dependsOnReactNative (native/ecosystem.ts) is the only signal for a declared package, and the closure walk starts only from detected packages.

Candidate: a runtime-imports signal. Detect a declared package whose runtime graph imports react-native, reusing runtimeImports(), which today serves the closure walk's peer edge.

  • Across three real apps it finds about 10 undeclared React Native libraries per app (moti, @react-native-community/slider, react-native-animatable, react-native-keychain, react-native-picker-select …).
  • It costs 258–671 ms per config evaluation (1.3k–2.5k files walked), so it needs a cache keyed by package directory and version.
  • Risk: each package it catches moves from Vite to Node ownership. That needs a corpus comparison against main before it ships.

A cheaper but narrower alternative: a source-entry signal (the entry the plugin resolves is .ts/.tsx/.jsx). It costs 12–24 ms and catches react-native-calendars, but it also moves packages that work today, such as Expo modules with a TypeScript entry.

Remaining 2: Metro-only source served by Vite

Past the JSX, react-native-calendars' src/interface.js uses require inside ES module source. Metro and babel-jest accept that mix; Vite's module runner and Node don't:

ReferenceError: require is not defined in ES module scope, you can use import instead
  node_modules/react-native-calendars/src/interface.js:1:15

Compiling the package as a detected one (Babel, CommonJS output) handles it, which is what transform: [...] does today. So part 2 is solved by part 1 for any package detection catches. A package left in Vite would need a load-time CommonJS compile of mixed source, which is not proposed.

Evidence (registry manifests)

  • react-native-calendars@1.1314.0: no react-native dependency or peer, and no react-native field or export condition. Its main is src/index.ts (TypeScript source), and it publishes JSX in .js files (src/calendar/index.js). Dependencies: recyclerlistview@^4.0.0, react-native-swipe-gestures@^1.0.5, xdate, lodash, prop-types, memoize-one, hoist-non-react-statics.
  • recyclerlistview@4.2.3: peer react-native, so it is detected when declared directly. It ships compiled dist/, so missing it through the closure doesn't break this package.
  • react-native-swipe-gestures@1.0.5: no react-native declaration; plain index.js.

Reproduced on main (6dbaa56) with React Native 0.86.3, React 19.2.3, @testing-library/react-native 13.3.3 and Vitest 5.0.5. Listing only react-native-calendars in transform makes <Calendar /> render.

Activity

  1. added this to the 0.16.0 milestone on Nov 11, 2026
  2. added
    bug
    priority:medium
    area:transform
    on Nov 11, 2026
  3. danfry1 commented on Nov 11, 2026

    @danfry1
    OwnerAuthor

    Reproduced on main (6dbaa56, packed tarball), engine native chosen by default, with React Native 0.86.3, React 19.2.3, @testing-library/react-native 13.3.3, Vitest 5.0.5 and react-native-calendars 1.1314.0 (with recyclerlistview 4.2.3 and react-native-swipe-gestures 1.0.5).

    A test that renders <Calendar current="2026-11-11" /> with a zero-config reactNative() fails before any test runs:

    Error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
      Plugin: vite:import-analysis
      File: node_modules/react-native-calendars/src/calendar/index.js:97:19
    

    The package publishes JSX in .js files under src/ (main is src/index.ts), and since it isn't detected, it stays in Vite's graph uncompiled.

    • transform: ['react-native-calendars'] alone makes it render and pass.
    • Adding recyclerlistview and react-native-swipe-gestures makes no difference here: recyclerlistview ships compiled dist/.

    So for this package the gap is the direct detection. Missing the closure would matter only for a dependency that also ships untranspiled source.

  4. danfry1 commented on Nov 11, 2026

    @danfry1
    OwnerAuthor

    Part of this lands in #767 (0.15.1): a package's .js file with JSX that Vite can't parse is now compiled at load under the native engine, so that parse error no longer stops the run. On react-native-calendars 1.1314.0 the run then reaches src/interface.js, which uses require inside ES module source. That needs the full compile a detected package gets, and the error names the package and reactNative({ transform: ['react-native-calendars'] }). Zero-config support for such packages stays open here for 0.16.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:transformbugpriority:medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions