react-native-skia
react-native-skia copied to clipboard
Error When Adding Text To Skia Web In My Project With Expo Router
Description
I am getting the following error when adding text to my RN Skia Web project which uses Expo Router:
Uncaught Error
_Image.default.resolveAssetSource is not a function
Here is my setup:
//text setup:
const fontSize = 32;
const font = useFont(require('../fonts/Roboto-Light.ttf'), fontSize);
...
<Text
x={100}
y={100}
text={"test"}
font={font}
size={32}
opacity={100}
/>
Version
0.1.172
Steps to reproduce
clone https://github.com/rarepython21/Skia-Text-Bug-w-Expo-Router
or
- npx create-expo-app@latest -e with-router
- skipped yarn add @shopify/react-native-skia or npm install @shopify/react-native-skia
- expo install @shopify/react-native-skia
- yarn setup-skia-web
- npm install copy-webpack-plugin --save-dev
- npm i node-polyfill-webpack-plugin
- setup webpack.config.js as outlined below 8. yarn add react-native-level-fs
- yarn add path-browserify
- added "fs": "react-native-level-fs", "path": "path-browserify", to my dependencies in package.json
- added skia to my index.js using code splitting
- yarn add path-browserify again
- got this Uncaught Error: Aborted(CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0). Build with -sASSERTIONS for more info.
- used CDN
- and add a Text object
webpack.config.js:
import CopyPlugin from "copy-webpack-plugin";
import NodePolyfillPlugin from "node-polyfill-webpack-plugin";
const newConfiguration = {
...currentConfiguration,
plugins: [
...currentConfiguration.plugins,
// 1. Make the wasm file available to the build system
new CopyPlugin({
patterns: [
{
from: "node_modules/canvaskit-wasm/bin/full/canvaskit.wasm",
},
],
}),
// 2. Polyfill fs and path module from node
new NodePolyfillPlugin()
],
externals: {
...currentConfiguration.externals,
// 3. Avoid warning if reanimated is not present
"react-native-reanimated": "require('react-native-reanimated')",
"react-native-reanimated/lib/reanimated2/core":
"require('react-native-reanimated/lib/reanimated2/core')",
},
}
Snack, code example, screenshot, or link to a repository
- seems to indicate that the wasm file wasn't found (despite the presence of the copy plugin). You can check if yourself in trying to access the wasm file via your local http url (http://localhost:3000/canvaskit.wasm) for instance.
@rarepython21 thank you for reporting this. We now support metro and expo-router in v0.1.240: https://shopify.github.io/react-native-skia/docs/getting-started/web#expo. I just tried it and it worked really well, let us know if you have any questions.