Skip to content

[Mobile] onnxruntime-react-native fails to load bundled ONNX assets in Expo standalone iOS #26738

@acrdlph

Description

@acrdlph

Describe the issue

Environment

  • React Native / Expo (standalone iOS build)
  • onnxruntime-react-native (version: 1.23.2)
  • Hermes
  • Models bundled via Metro using expo-asset

Problem

In the Expo dev client, loading a bundled model via
Asset.fromModule(...).localUri works.

In the standalone iOS build,
InferenceSession.create(localUri) fails when the model stays in the app bundle.

  • The localUri is a file:// path inside the app bundle.
  • The session init fails with a generic “failed to load model” error.
  • No model bytes are read unless we first copy the file out of the bundle.

Observed Behavior

  • InferenceSession.create rejects when uri points to the bundled file
    (file://... in the app sandbox).
  • No clear error about:
    • Path scheme
    • Bundle accessibility

Workaround Applied

Copy the bundled model to a writable path before loading:

const dest =
  FileSystem.documentDirectory + basename(asset.localUri);

await FileSystem.copyAsync({
  from: asset.localUri,
  to: dest,
});

To reproduce

In an expo project with onnxruntime-react-native installed:

  1. Bundle a model (e.g., silero_vad_v5.onnx) via require(...).
  2. Resolve with:
    • const asset = Asset.fromModule(mod);
    • await asset.downloadAsync();
    • const uri = asset.localUri;
  3. Call InferenceSession.create(uri) (or the equivalent load API).
  4. Observe failure in a standalone iOS build; the same code works in the Expo dev client.

Urgency

Not urgent, since workaround found.

Platform

iOS

OS Version

26

ONNX Runtime Installation

Released Package

Compiler Version (if 'Built from Source')

No response

Package Name (if 'Released Package')

onnxruntime-react-native

ONNX Runtime Version or Commit ID

1.23.2

ONNX Runtime API

Other / Unknown

Architecture

Other / Unknown

Execution Provider

Other / Unknown

Execution Provider Library Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform:mobileissues related to ONNX Runtime mobile; typically submitted using templateplatform:webissues related to ONNX Runtime web; typically submitted using template

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions