microsoft / microsoft/onnxruntime

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

Open
#26,738 3 comments 0 reactions 2 assignees View on GitHub

Nobody has claimed this yet.

platform:mobile platform:web
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 11h
Merged PRs (30d)
184

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.