-
Notifications
You must be signed in to change notification settings - Fork 2k
Import tfjs-react-native not working on EXPO CLI Project #2784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
From your error it looks like you are using webpack (as opposed to metro) to bundle your app. I think you need to configure webpack to process .js files (or even that specific js file) with the JSX loader (or some transformer that can consume jsx syntax). |
It doesn't seem related to JSX syntax because other JSX components are being rendered properly. The problem occurs as soon as I import @tensorflow/tfjs-react-native. From the Error Log, could it be related to this: microsoft/TypeScript#30650 I am using Expo Managed app. |
@DanielOnye123 I don't know how to do this. I haven't been using webpack in concert with RN apps. @muditgoel01 I don't think its related to typescript as the files in the package are already transpiled to JavaScript. In this case it may be that the bundler is configured to assume all components are in files with the .jsx extension. Are you able to load JSX components that are within .js files? |
I would suggest asking on Stack Overflow or the Expo forums for more info on configuration options for the setup you are using. It could be a recent change in expo. |
Could you test this by If that works, then it helps narrow down where a configuration issue may be. |
I'm able to import and render without the tfjs-react module. I do believe this could be a configuration issue because I tested this on an Expo managed app with typescript configuration and the import worked |
Downgrading to "@tensorflow/tfjs-react-native": "0.1.0-alpha.2" works fine. |
@DanielOnye123 are you able to import a JSX component that is in a .js file? |
@tafsiri Yes. I am able to |
@DanielOnye123 Were you getting this unexpected token error in your project only when doing Try running const createExpoWebpackConfigAsync = require('@expo/webpack-config');
const path = require('path');
module.exports = async function(env, argv) {
const config = await createExpoWebpackConfigAsync(env, argv);
config.module.rules.push({
test: /\.(js|jsx)$/,
include: [path.resolve(__dirname, "node_modules/@tensorflow/tfjs-react-native")],
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/env', { modules: 'commonjs' }],
],
}
}
});
return config;
}; I was able to get my managed Expo JS app working on the web with this. |
Thank you. It's working on the web, but ironically it's not working on the android. I keep getting this error above. I checked out this other documentation with a similar issue: Issue, but his solution didn't work for me as I don't have typescript config |
That
Then metro should stop complaining. |
Thank you so much! It's working on both platforms. My last question is: Does the "fetch" method imported from tfjs-react native support local fetches? e.g locally fetching a picture |
Hi, I don't have experience with ReactNative/NodeJs and just tried everything you explained here, but still, have the same problems. Can you please, provide the example code?. I am running on MacOs, node 13, expo cli. - My hello world RN app is working, but when I add your code - I got the same errors. |
Doesn't seem like fetch supports local afaik. Might have to use expo-file-system to load local images for now. @motya770 Which error are you getting? I have a barebones TF.js typescript expo managed project that can load fine for me (https://github.com/pvaneck/tfjs-react-native-app) if you want to check that out. |
@pvaneck fetch seems to be working fine in ios but fails on android |
Hi, I just switched to Flutter, much simpler, much more predictable results ) |
Looks like this has been resolved. +1 to the comment on using something like expo-file-system to read local files. Feel free to leave a comment/file a new issue if this is still unresolved. |
Describe the problem or feature request
I'm getting this error when I try to run my React-Native program on the web or android. I followed the steps on the tfjs-react-native documentation but I'm still having issues with my program.
TensorFlow.js version
tfjs-react-native
Browser version
package.json

Code to reproduce the bug / link to feature request
This is the code causing the error

I even removed the tfjs-react native import and it compiles so I don't know what to do
If you would like to get help from the community, we encourage using Stack Overflow and the
tensorflow.js
tag.GitHub issues for this repository are tracked in the tfjs union repository.
Please file your issue there, following the guidance in that issue template.
The text was updated successfully, but these errors were encountered: