[JS] Using Yoga npm version 3.1.0 with Expo/React Native #1738

Closed
opened 2024-11-05 06:22:58 -08:00 by Omxjep3434 · 2 comments
Omxjep3434 commented 2024-11-05 06:22:58 -08:00 (Migrated from github.com)

Report

I created a Javascript library that uses Yoga and I'm trying to use it in an Expo project, and I see multiple errors related to the Yoga npm package.

Environment:
Windows 11
Running the Android app, although this shouldn't matter
Expo version: "~51.0.28"
React Native version: "0.74.5"
Yoga version: "3.1.0"

Issues and Steps to Reproduce

  1. Run npx create-expo-app
  2. Run npm install yoga-layout
  3. Add the following to index.tsx: import { loadYoga } from "yoga-layout/load";
  4. Run expo start

Encountered problems

  1. yoga-layout/load won't be resolved because Metro doesn't support export maps by default. You need to create a metro.config.js file and add config.resolver.unstable_enablePackageExports = true;
  2. I now get the error: SyntaxError: 448247:22:'import.meta' is currently unsupported, js engine: hermes
  3. Since the error above seems related to the hermes engine, I tried setting "jsEngine": "jsc" in app.json and I now get this error: The package at "node_modules\yoga-layout\dist\binaries\yoga-wasm-base64-esm.js" attempted to import the Node standard library module "url". It failed because the native React runtime does not include the Node standard library.

Are there any ideas to solve this or any interest in making the npm package work with Expo/React Native? I'm wondering if I should give up on supporting React Native with my Javascript library.

# Report I created a Javascript library that uses Yoga and I'm trying to use it in an Expo project, and I see multiple errors related to the Yoga npm package. Environment: Windows 11 Running the Android app, although this shouldn't matter Expo version: "~51.0.28" React Native version: "0.74.5" Yoga version: "3.1.0" # Issues and Steps to Reproduce 1. Run `npx create-expo-app` 2. Run `npm install yoga-layout` 3. Add the following to index.tsx: `import { loadYoga } from "yoga-layout/load";` 4. Run `expo start` # Encountered problems 1. yoga-layout/load won't be resolved because Metro doesn't support export maps by default. You need to create a metro.config.js file and add `config.resolver.unstable_enablePackageExports = true;` 2. I now get the error: SyntaxError: 448247:22:'import.meta' is currently unsupported, js engine: hermes 3. Since the error above seems related to the hermes engine, I tried setting `"jsEngine": "jsc"` in app.json and I now get this error: The package at "node_modules\yoga-layout\dist\binaries\yoga-wasm-base64-esm.js" attempted to import the Node standard library module "url". It failed because the native React runtime does not include the Node standard library. Are there any ideas to solve this or any interest in making the npm package work with Expo/React Native? I'm wondering if I should give up on supporting React Native with my Javascript library.
NickGerleman commented 2024-11-05 08:50:35 -08:00 (Migrated from github.com)

Apart from all the toolchain/esm/emcripten environment detection bits, RN doesn’t support WebAssembly, and we’re no longer distributed asm.js binaries. Asm.js yoga against Hermes was attempted before, but from some earlier bug report I’m having trouble finding, its performance and memory characteristics made it unusable.

This is annoying for making a cross platform library that works everywhere, but for isolated cases where you want to expose Yoga as a JavaScript API, C++ turbo modules could be used to hook a native version of Yoga.

Apart from all the toolchain/esm/emcripten environment detection bits, RN doesn’t support WebAssembly, and we’re no longer distributed asm.js binaries. Asm.js yoga against Hermes was attempted before, but from some earlier bug report I’m having trouble finding, its performance and memory characteristics made it unusable. This is annoying for making a cross platform library that works everywhere, but for isolated cases where you want to expose Yoga as a JavaScript API, C++ turbo modules could be used to hook a native version of Yoga.
Omxjep3434 commented 2024-11-05 14:09:20 -08:00 (Migrated from github.com)

Ah, well I guess that's definitely not going to work. Thanks Nick, I'll close the issue.

Ah, well I guess that's definitely not going to work. Thanks Nick, I'll close the issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#1738
No description provided.