cawfree / react-native-webassembly

⚛️ 🏎 WebAssembly for React Native powered by JSI.
https://twitter.com/cawfree
MIT License
329 stars 6 forks source link

can not build #11

Closed iwater closed 1 year ago

iwater commented 1 year ago
截屏2023-05-15 17 23 26
cawfree commented 1 year ago

Hi, I just tried to install the latest version of react-native-webassembly as follows:

npx create-react-native-app -t with-typescript xxx
cd xxx
yarn add react-native-webassembly axios
npx expo prebuild
cd ios && pod install
cd ..
yarn ios

Then I loaded up some simple example inside App.tsx:

import * as React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import * as WebAssembly from 'react-native-webassembly';
import axios from 'axios';

export default function App() {

  React.useEffect(() => void (async () => {

    try {
      const {data} = await axios({
        url: 'https://github.com/torch2424/wasm-by-example/raw/master/examples/hello-world/demo/assemblyscript/hello-world.wasm',
        method: 'get',
        responseType: 'arraybuffer',
      });
      const x = await WebAssembly.instantiate<{add: (a: number, b: number) => number}>(data);
      console.warn(x.instance.exports.add(1000, 2000));
    } catch (e) {
      console.error(e);
    }

  })(), []);

  return (
    <View style={styles.container}>
      <Text>Open up App.tsx to start working on your app!</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

This works as expected.

This may suggest a configuration issue with your project; the MutableMemoryHeaderBuffer class in particular expects to be derived from React Native's MutableBuffer.

It could be a couple of things:

It could also be some other configuration issues, but these would be my bet.

iwater commented 1 year ago

I use 0.69.10 with hermes enable, when installed react-native-webassembly@0.3.2, build without error, so is react-native-webassembly@0.3.3 only support 0.71.1+ ?

cawfree commented 1 year ago

I use 0.69.10 with hermes enable, when installed react-native-webassembly@0.3.2, build without error, so is react-native-webassembly@0.3.3 only support 0.71.1+ ?

Hey @iwater, sorry for the delay getting back to you. I believe this was one of those move-fast-break-things situations when we had basically zero users.

Hope you were able to make the upgrade and it wasn't too painful (but hey, it's React Native).