NodeJs: Getting "Error: The specified module could not be found..." while importing @tensorflow/tfjs-node library

846 views
Skip to first unread message

Shariq Azim

unread,
Apr 27, 2020, 1:16:53 PM4/27/20
to TensorFlow.js Discussion
Hi All,
Need some help in importing the node binding in NodeJs.
I am getting the "Error: The specified module could not be found\\?\C:\Program Files\nodejs\tf\node_modules\@tensorflow\tfjs-node\lib\napi-v5\tf js_binding.node", 
which however is present in the path.

TensorFlow.js version- 1.7.3

Platform information: 
Windows: 8.1 
Python: 2.7.12 
npm: 6.14.4
node: 10.20.1

Please find the attached screenshots for your reference. 


Please also note. I have most of the steps 

Requesting some guidance on the same.

Regards,
Shariq

node eror.JPG
node file.JPG

Jason Mayes

unread,
Apr 27, 2020, 1:39:02 PM4/27/20
to TensorFlow.js Discussion
Can you confirm if a simple Node program works eg an express server or hello world or such just to confirm other modules working on your PC?  

Can you also try npm install -u for tfjs so it installs at user level in case its some visibility issue with folder it got downloaded to etc?

Let me know if those work just so I have a better idea of environment.

J

Shariq Azim

unread,
May 1, 2020, 10:43:48 AM5/1/20
to TensorFlow.js Discussion
Hello Jason,

Thanks for reaching out and sorry for not checking and replying earlier than today.
Please find my response below highlighted in yellow. Btw please note the index.js will run when i run just 
const tf= require('@tensorflow/tfjs');


But will fail, when i do:
require('@tensorflow/tfjs-node');

Please also find the full code which could not be as basic as this.
console.log("HI");
const tf= require('@tensorflow/tfjs');
require('@tensorflow/tfjs-node');

Train a simple model:
const model = tf.sequential();
model.add(tf.layers.dense({units: 100, activation: 'relu', inputShape: [10]}));
model.add(tf.layers.dense({units: 1, activation: 'linear'}));
model.compile({optimizer: 'sgd', loss: 'meanSquaredError'});

const xs = tf.randomNormal([100, 10]);
const ys = tf.randomNormal([100, 1]);

model.fit(xs, ys, {
  epochs: 100,
  callbacks: {
    onEpochEnd: (epoch, log) => console.log(`Epoch ${epoch}: loss = ${log.loss}`),
  }
});




Regards,
Shariq

On Monday, April 27, 2020 at 11:09:02 PM UTC+5:30, Jason Mayes wrote:
Can you confirm if a simple Node program works eg an express server or hello world or such just to confirm other modules working on your PC?  - Yes it works like that. And as you observe the  "node error.jpg" attachments in the first email. You  should  observe that "Hi" was printed before the error  was shown.

Can you also try npm install -u for tfjs so it installs at user level in case its some visibility issue with folder it got downloaded to etc?- I did this too as per your suggestion, but didnt work :) 

Jason Mayes

unread,
May 1, 2020, 3:27:12 PM5/1/20
to Shariq Azim, TensorFlow.js Discussion
To import TF.js in Node you should follow this guide:


Should only have 1 import as far as I can see, you have 2.

Jason
 

--
You received this message because you are subscribed to the Google Groups "TensorFlow.js Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfjs+uns...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfjs/83c4be57-7e35-415a-8aaf-3e1c0d524a9b%40tensorflow.org.


--




     
  •  Jason Mayes
  •  Senior Developer Advocate, TensorFlow.js
  •  Google
     Follow my discoveries or contribute your own

   

This email may be confidential and privileged. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.


Reply all
Reply to author
Forward
0 new messages