2

I am trying to get tensorflow working in my electron app using tensorflow js.

Here are the details of the various versions:

Nodejs: v14.4.0 @tensorflow/tfjs - 2.0.0 @tensorflow/tfjs-node - 2.0.0 electron - 1.8.8

When I try to load the tfjs module using:

const tf = require('@tensorflow/tfjs');

I get the following error: enter image description here

I have looked everywhere but can't seem to find anything relevant for this error.

Any help would be much appreciated.

Arun Krishnan
  • 211
  • 1
  • 3
  • 10
  • Could you please downgrade to node 10 or 12 and see if the issue still occurs ? – edkeveked Jun 05 '20 at 12:35
  • Hi, Thanks for responding. I started off with 8.10 then 12.8 and then 14.4. I saw the documentation for v14.4 and see that util.Encoder is present. https://nodejs.org/api/util.html Perhaps I should clear out the node_modules folder and try again? – Arun Krishnan Jun 05 '20 at 14:13
  • And what is the result after trying ? – edkeveked Jun 05 '20 at 14:40
  • So I just renamed the node_modules directory to node_modules_orig and did `npm install electron` It installed all the modules including tensorFlow. I still got the same error. Is there a cleaner way of doing this? – Arun Krishnan Jun 05 '20 at 15:01
  • Are you sure that only loading `@tensorflow/tfjs` causes the error ? – edkeveked Jun 05 '20 at 15:08
  • Yes. When I comment that line out, no problems. I looked into that file. – Arun Krishnan Jun 05 '20 at 15:11
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/215380/discussion-between-edkeveked-and-arun-krishnan). – edkeveked Jun 05 '20 at 15:11

1 Answers1

0

SOLUTION

The issue seems to be one of competing libraries. Although I don't know exact which library, found a workaround which involved installing @tensorflow/tfjs first followed by all other libraries.

Thanks to @edkeveked for all his help.

The solution is to

  1. Create a new electron project
  2. Install electron followed by @tensorflow/tfjs
  3. Install all other required modules
  4. Move the node_modules directory from this to my original app directoy.

Hope this helps someone else facing this issue.

Arun Krishnan
  • 211
  • 1
  • 3
  • 10