Skip to content

[runtime not ready]: Error: Dynamic require defined at line 9; not supported by Metro, js engine: hermes #13

@TowhidKashem

Description

@TowhidKashem

Hi, thanks a lot for the lib. It would be amazing to be able to run transformers js models on device since they work so well on the browser! But I'm running into an error trying to get the sample code from the README working but running into this error when starting the app:

[runtime not ready]: Error: Dynamic require defined at line 9; not supported by Metro, js engine: hermes

Image

It's happening for both the snippet under "Text Generation" and "With Custom Model Download".

✅ I did include the babel-plugin-transform-import-meta plugin in babel config, I also tried by setting the unstable_transformImportMeta experimental flag for babel-preset-expo when the above didn't work (but still got same error):

module.exports = (api) => {
  api.cache(true);
  return {
    presets: [
      [
        'babel-preset-expo',
        {
          // NOTE: I confirmed these 2 other options aren't the cause by commenting them out and the error remained
          lazyImports: true,
          native: {
            // disable redundant ESM -> CJS compilation because metro already does it
            disableImportExportTransform: true
          }
          // unstable_transformImportMeta: true
        }
      ]
    ],
    plugins: [
      [
        'module-resolver',
        {
          root: ['./'],
          alias: {
            '.....'
          }
        }
      ],
      'babel-plugin-transform-import-meta',
      'react-native-reanimated/plugin'
    ],
    env: {
      production: {
        plugins: ['transform-remove-console']
      }
    }
  };
};

✅ I did include the expo config plugin to app config:

{ "expo": { "plugins": ["onnxruntime-react-native"] } }

My metro.config.js:

const path = require('path');
const { getSentryExpoConfig } = require('@sentry/react-native/metro');
const {
  wrapWithReanimatedMetroConfig
} = require('react-native-reanimated/metro-config');

const projectRoot = __dirname;

/** @type {import('expo/metro-config').MetroConfig} */
const config = getSentryExpoConfig(projectRoot);

// monorepo support (dev only)
if (!process.env.EAS_BUILD) {
  const monorepoRoot = path.join(projectRoot, '../..');

  const monorepoPackages = {
    'utils-shared': path.join(monorepoRoot, 'packages/utils-shared'),
    '@types.server': path.join(monorepoRoot, 'apps/server/@types.server')
  };

  config.watchFolders = [projectRoot, ...Object.values(monorepoPackages)];

  config.resolver.extraNodeModules = monorepoPackages;

  config.resolver.nodeModulesPaths = [
    path.join(projectRoot, 'node_modules'),
    path.join(monorepoRoot, 'node_modules')
  ];
}

// NOTE: Added these just to be safe but still same error, removing them makes no difference
config.resolver.assetExts.push('onnx', 'ort', 'pte', 'bin', 'lottie');

config.resolver.disableHierarchicalLookup = true;
config.resolver.unstable_enableSymlinks = true;

module.exports = wrapWithReanimatedMetroConfig(config);

Testing on simulator iPhone Pro Max, iOS 18.2, full result for npx expo-info:

expo-env-info 1.3.3 environment info:
  System:
    OS: macOS 15.5
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.19.2 - /opt/homebrew/opt/node@20/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.8.2 - /opt/homebrew/opt/node@20/bin/npm
    Watchman: 2025.05.26.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.16.2 - /Users/towhidkashem/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 24.5, iOS 18.5, macOS 15.5, tvOS 18.5, visionOS 2.5, watchOS 11.5
  IDEs:
    Xcode: 16.4/16F6 - /usr/bin/xcodebuild
  npmPackages:
    expo: 53.0.11 => 53.0.11 
    expo-updates: ~0.28.14 => 0.28.15 
    react: 19.0.0 => 19.0.0 
    react-native: ^0.79.2 => 0.79.5 
  Expo Workflow: managed

This is on the new architecture btw Expo SDK 53 with custom dev client.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions