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: env().platform.isTypedArray is not a function. (In 'env().platform.isTypedArray(a)', 'env().platform.isTypedArray' is undefined) #7273

Closed
anglo2333 opened this issue Jan 14, 2023 · 21 comments · Fixed by #7489
Assignees
Labels
type:bug Something isn't working

Comments

@anglo2333
Copy link

Please make sure that this is a bug. As per our
GitHub Policy,
we only address code/doc bugs, performance issues, feature requests and
build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js):
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow.js installed from (npm or script link):
  • TensorFlow.js version (use command below):
  • Browser version:
  • Tensorflow.js Converter Version:

Describe the current behavior

Describe the expected behavior

Standalone code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate
the problem. If possible, please share a link to Colab/CodePen/any notebook.

Other info / logs Include any logs or source code that would be helpful to
diagnose the problem. If including tracebacks, please include the full
traceback. Large logs and files should be attached.

@anglo2333 anglo2333 added the type:bug Something isn't working label Jan 14, 2023
@AlexGurski
Copy link

use the previous version, for example @4.1.0

@asallem94
Copy link

I am running into this issue with a react-native project.

@Rhysjc
Copy link
Contributor

Rhysjc commented Jan 16, 2023

Experiencing the same issue with a new react-native project. Downgrading to 4.1.0 didn't help.

@anglo2333
Copy link
Author

anglo2333 commented Jan 16, 2023 via email

@Rhysjc
Copy link
Contributor

Rhysjc commented Jan 16, 2023

Having done some digging, I think #7181 introduced this. I assume isTypedArray needs to be added to the React Native platform

@Rhysjc
Copy link
Contributor

Rhysjc commented Jan 16, 2023

tfjs-react-native has tfjs-core as a peer dependency on version 3.7.0 (which doesn't include isTypedArray in the Platform type). I'm not too sure how the versioning of the packages here work, but assuming tfjs follows the same versions, downgrading @tensorflow/tfjs to 3.7.0 in your React Native project may resolve this. I don't have time to try it right now but I will do tomorrow. If this resolves it for anyone please comment.

Edit:
Confirmed that installing @tensorflow/tfjs at 3.7.0 resolves this issue. If someone can provide some direction on how I can correctly update the peer dependencies in tfjs-react-native and update the platform file I'm happy to submit a PR

@huhm
Copy link

huhm commented Jan 17, 2023

use the previous version, for example @4.1.0

it works for me. I used the tsjs-node

@Rhysjc
Copy link
Contributor

Rhysjc commented Jan 17, 2023

@huhm potentially I just needed to clear my metro cache and 4.1.0 would have worked. Though I think it's probably best to use the version tfjs-react-native has listed as a peer dependency

@Deeparaj-24
Copy link

4.1.0

After dowgrade ,getting same error bro

@ToonTalk
Copy link

4.1.0 fixed it for me - not using native react

@yousefamar
Copy link

React Native Expo standalone workflow developers: you need to create a new development build. Downgrading to 3.7.0 worked for me after doing that

@hrshlmeht
Copy link

Hi , thanks for mentioning it. I am facing the same issue. Although my application is in NodeJs environment is this going to work? Because downgrading and having its repercussion on other working models can also be an issue later.

Please let me know

@abhik-wil
Copy link

Hi , thanks for mentioning it. I am facing the same issue. Although my application is in NodeJs environment is this going to work? Because downgrading and having its repercussion on other working models can also be an issue later.

Please let me know

Hey, so I am using Vite/React and downgrading to 3.7.0 worked for me.

@IvanKuchin
Copy link

Hi,

There are many examples failing on TFJS API web-site.
Just as an example (tfjs-vis):
image

@DavidODonovan
Copy link

I had the same problem whilst using Vite/React app. Fixed it by downgrading to TFJS to version 3.7.0.
Thanks @abhik Banerjee

@delirium15
Copy link

Also had same problem, but only when going to target page (containing tfjs logic) from another page. Reloading that page didn't produced that error. Using Nuxt3 / Vite.
Downgrading from 4.2.0 to 4.1.0 didn't help, but to 3.7.0 solved problem.

@BruceDai
Copy link
Contributor

Also had same problem of running tests by CPU backend, downgrading to 4.1.0 worked.
Any update for this fixing, thanks.

mattsoulanille added a commit to mattsoulanille/tfjs that referenced this issue Mar 16, 2023
A new function, `isTypedArray` was added to the `platform` interface by tensorflow#7181
and first published in tfjs-core 4.2.0. This made 4.2.0 incompatible with
earlier versions of backends that implemented `platform`, such as node and
react-native. This change adds a fallback to the use of `isTypedArray` so
earlier versions of platforms that don't implement `isTypedArray` will not throw
an error. Note that the behavior may not be perfect, such as when running Jest
tests in node. See tensorflow#7175 for more details and upgrade all @tensorflow scoped
packages to ^4.2.0 to avoid this.

Fixes tensorflow#7273
mattsoulanille added a commit to mattsoulanille/tfjs that referenced this issue Mar 16, 2023
A new function, `isTypedArray` was added to the `platform` interface by tensorflow#7181
and first published in tfjs-core 4.2.0. This made 4.2.0 incompatible with
earlier versions of backends that implemented `platform`, such as node and
react-native. This change adds a fallback to the use of `isTypedArray` so
earlier versions of platforms that don't implement `isTypedArray` will not throw
an error.

Note that the fallback behavior may not be perfect, such as when running Jest
tests in node. See tensorflow#7175 for more details and upgrade all @tensorflow scoped
packages to ^4.2.0 to avoid this.

Fixes tensorflow#7273
@google-ml-butler
Copy link

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

@ianmaddox
Copy link

ianmaddox commented Apr 4, 2023

Had same issue trying to add an lstm layer to an empty model using 4.2.0:

    const model = tf.sequential();

    model.add(tf.layers.lstm({
        inputShape: [null, numFeatures],
        units: 64,
        returnSequences: true
    }));

generated the following error

/dir/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:2978
    return env().platform.isTypedArray(a);
                          ^

TypeError: env(...).platform.isTypedArray is not a function
    at isTypedArray (/dir/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:2978:27)
    at inferShape (/dir/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:5428:9)
    at tensor1d (/dir/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:18528:25)
    at /dir/node_modules/@tensorflow/tfjs-node/dist/kernels/SplitV.js:45:45
    at /dir/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4506:22
    at Engine.scopedRun (/dir/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4516:23)
    at Engine.tidy (/dir/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4505:21)
    at tidy (/dir/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:8053:19)
    at Object.kernelFunc (/dir/node_modules/@tensorflow/tfjs-node/dist/kernels/SplitV.js:44:32)```

Backing down to 4.1.0 fixed it.

@Merub-810
Copy link

@Rhysjc which version of react native you are using because in my case 3..7.0. is incompatible with my react native version

@JRfan123
Copy link

JRfan123 commented Jun 2, 2024

@Rhysjc which version of react native you are using because in my case 3..7.0. is incompatible with my react native version

me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.