Skip to content
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

TypeError: undefined is not an object (evaluating 'env().platform.encode') #8349

Closed
gameveloster opened this issue Aug 2, 2024 · 4 comments
Assignees

Comments

@gameveloster
Copy link

I'm having issues using tfjs in Expo app.

Getting the error:

TypeError: undefined is not an object (evaluating 'env().platform.encode')

when trying to use tf.util.encodeString:

import * as tf from "@tensorflow/tfjs";
import * as ImageManipulator from "expo-image-manipulator";

export default function MyScreen() {
    const resizedImage = await ImageManipulator.manipulateAsync(
        imageUri,
        [{ resize: { width: 640, height: 640 } }],
        { format: ImageManipulator.SaveFormat.PNG, base64: true }
    );

    const imgBuffer = tf.util.encodeString(
        resizedImage.base64,
        "base64"
    ).buffer;

    // ...
}

Anyone encountered this before?

My app has installed [email protected], @tensorflow/[email protected]

@gameveloster gameveloster added the type:bug Something isn't working label Aug 2, 2024
@gaikwadrahul8 gaikwadrahul8 self-assigned this Aug 5, 2024
@shmishra99 shmishra99 self-assigned this Aug 28, 2024
@shmishra99
Copy link
Contributor

Hi @gameveloster,

Apologies for the delayed response.

I was able to successfully convert the base64 image string into a base64 Uint8Array using the code snippet you provided. Here is the code I used:

const resizedImage = await ImageManipulator.manipulateAsync(
  selectedImage,
  [{ resize: { width: 640, height: 640 } }],
  { format: ImageManipulator.SaveFormat.PNG, base64: true }
);
const resizedImagBase = resizedImage.base64 ??  ''; 
console.log("resizedImage..", resizedImagBase)
const imgBuffer = tf.util.encodeString( resizedImagBase
  , 'base64').buffer;
console.log("imgBuffer",imgBuffer)

This code results in a Uint8Array, as shown in the attached image.

image

The error suggests that the env() function might not be properly initialized, as referenced in environment.ts.

Please try the following troubleshooting steps:

 1) Delete your node_modules folder.
 2) Remove the package-lock.json or yarn.lock file.
 3) Reinstall all dependencies using `npm install`.

Let me know if this resolves the issue.

Thank you!

Copy link

github-actions bot commented Sep 5, 2024

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale label Sep 5, 2024
Copy link

This issue was closed due to lack of activity after being marked stale for past 7 days.

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants