Error: Cannot find module '.../node_modules/@tensorflow/tfjs-node/lib/napi-v4/tfjs_binding.node'
To get help from the community, we encourage using Stack Overflow and the tensorflow.js tag.
TensorFlow.js version
"@tensorflow/[email protected]":
Browser version
Describe the problem or feature request
Error: Cannot find module '.../node_modules/@tensorflow/tfjs-node/lib/napi-v4/tfjs_binding.node'
Workaround:
npm rebuild @tensorflow/tfjs-node --build-from-source
@haoyangnz what's the operating system you are using?
@kangyizhang macos mojave 10.14.6
@haoyangnz
- did you see any error or warning logs while installing @tensorflow/tfjs-node?
- what's your node version?
- can you provide the full error stack trace?
@kangyizhang hi there, I got the same issue here.
- no error when installing
- node -v
v10.16.0 - Error: Cannot find module '/Users/blabla/Documents/test/tensorflowjs-iris/node_modules/@tensorflow/tfjs-node/lib/napi-v4/tfjs_binding.node'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.
(/Users/blabla/Documents/test/tensorflowjs-iris/node_modules/@tensorflow/tfjs-node/dist/index.js:44:16) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3)
hi @imnaifu can you provide what's the operating system you are using? can you successfully run the official tfjs-node example?
Hey @kangyizhang, it looks like I'm having the same issues.
Node v10.16.3
Npm 6.9.0
Mac OS 10.14.6 - MacBook Pro
Successfully ran tfjs-node example
Extra context
I'm using tfjs in a Vue.js / Electron app. I just factory restored my machine, on which everything was working before the reset. I also got this error on another MacBook ( Air ) which I had been using as a loner.
I'm also getting node-gyp errors, which seems to be related.
node-pre-gyp info This Node instance does not support builds for N-API version 4
This error occurs when I run my app for development using npm run electron:serve.
I have verified I have xcode-cli tools installed. Default Python 2.7.x is installed. I have cleared npm cache and node_modules a multiple times.
Are there any C/C++ dependencies I should check for?
I also got some errors warning about what looked like C++ library deprecations dealing with NaN. But I can't reproduce those currently.
Full error text
internal/modules/cjs/loader.js:602 Uncaught Error: Cannot find module '/Users/ericschirtzinger/Code/projects/samply/samply-desktop/node_modules/@tensorflow/tfjs-node/lib/napi-v3/tfjs_binding.node'
at Module._resolveFilename (internal/modules/cjs/loader.js:602)
at Function.Module._resolveFilename (/Users/ericschirtzinger/Code/projects/samply/samply-desktop/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/common/reset-search-paths.js:35)
at Function.Module._load (internal/modules/cjs/loader.js:528)
at Module.require (internal/modules/cjs/loader.js:658)
at require (internal/modules/cjs/helpers.js:20)
at Object.<anonymous> (/Users/ericschirtzinger/Code/projects/samply/samply-desktop/node_modules/@tensorflow/tfjs-node/dist/index.js:44)
at Object.<anonymous> (/Users/ericschirtzinger/Code/projects/samply/samply-desktop/node_modules/@tensorflow/tfjs-node/dist/index.js:66)
at Module._compile (internal/modules/cjs/loader.js:711)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:722)
at Module.load (internal/modules/cjs/loader.js:620)
hi @eschirtz
- with which version of tfjs-node are you seeing this error?
- if you clone repo @tensorflow/tfjs, go to folder tfjs-node, then run
yarn && yarn test, can you paste the output here? Thanks
- I had
^1.0.2, but I just upgraded to latest1.2.10and received the same error - Tests output below
yarn run v1.19.0
warning package.json: No license field
$ ts-node src/run_tests.ts
2019-10-04 18:00:26.012348: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Running tests against TensorFlow: 1.14.0
Started
....................................
============================
Hi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.
============================
.................Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.
......Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.
.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon You can disable deprecation warnings with tf.disableDeprecationWarnings().
tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon You can disable deprecation warnings with tf.disableDeprecationWarnings().
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................2019-10-04 18:00:28.528127: W tensorflow/core/framework/op_kernel.cc:1502] OP_REQUIRES failed at gather_nd_op.cc:47 : Invalid argument: indices must be at least a vector
.2019-10-04 18:00:28.528540: W tensorflow/core/framework/op_kernel.cc:1502] OP_REQUIRES failed at gather_nd_op.cc:47 : Invalid argument: params must be at least a vector
.2019-10-04 18:00:28.530295: W tensorflow/core/framework/op_kernel.cc:1502] OP_REQUIRES failed at gather_nd_op.cc:47 : Invalid argument: index innermost dimension length must be <= params rank; saw: 3 vs. 2
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................Found NaN in the result of 'test'
.Found Infinity in the result of 'test'
................................................................................................................................................................................................................................Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.
.................................................Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.
...............................................................................................................................................................
Ran 3410 of 3467 specs
3410 specs, 0 failures
Finished in 4.478 seconds
✨ Done in 6.39s.
Thanks!
Wanted to drop in my package.json as well. This project does work on my colleagues Windows & Linux machines, just not the Mac Computers I have been using.
{
"name": "Samply",
"version": "0.1.3",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"dev": "vue-cli-service electron:serve",
"build": "vue-cli-service electron:build",
"electron:generate-icons": "electron-icon-builder --input=./public/icon.png --output=build --flatten",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps",
"test:unit": "vue-cli-service test:unit",
"publish": "vue-cli-service electron:build -p always"
},
"dependencies": {
"@mdi/js": "^3.8.95",
"@tensorflow/tfjs": "^1.0.2",
"@tensorflow/tfjs-node": "^1.2.10",
"audio-decode": "^1.4.0",
"core-js": "^2.2.1",
"d3": "^5.9.2",
"electron-updater": "^4.0.6",
"eslint-plugin-html": "^5.0.3",
"firebase": "^6.3.4",
"glob": "^7.1.3",
"howler": "^2.1.1",
"material-design-icons-iconfont": "^4.0.5",
"music-metadata": "^3.8.0",
"node-wav": "^0.0.2",
"three": "^0.107.0",
"vue": "^2.6.6",
"vue-router": "^3.0.1",
"vuetify": "^2.0.7",
"vuex": "^3.0.1",
"vuex-persistedstate": "^2.5.4"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.4.0",
"@vue/cli-plugin-eslint": "^3.4.0",
"@vue/cli-plugin-unit-jest": "^3.7.0",
"@vue/cli-service": "^3.7.0",
"@vue/eslint-config-airbnb": "^4.0.0",
"@vue/test-utils": "1.0.0-beta.29",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"electron": "^3.1.9",
"electron-icon-builder": "^1.0.0",
"eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0",
"eslint-plugin-vuetify": "^1.0.0-beta.3",
"rollup": "^1.10.1",
"sass": "^1.22.9",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"vue-cli-plugin-electron-builder": "^1.1.3",
"vue-template-compiler": "^2.5.21",
"worker-loader": "^2.0.0"
},
"main": "background.js"
}
Same issue
I did as mentioned here https://www.tensorflow.org/js/tutorials/setup
yarn add @tensorflow/tfjs-node
then run the example
node example.js
const tf = require('@tensorflow/tfjs');
// Optional Load the binding: // Use '@tensorflow/tfjs-node-gpu' if running with GPU. 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}`) } });
and get this Error Error: Cannot find module 'path\node_modules@tensorflow\tfjs-node\lib\napi-v4\tfjs_binding.node' Require stack:
- path\node_modules@tensorflow\tfjs-node\dist\index.js
- path\example.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:780:15)
at Function.Module._load (internal/modules/cjs/loader.js:685:27)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.
(E:\AI\tensorflow\node_modules@tensorflow\tfjs-node\dist\index.js:44:16)
at Module._compile (internal/modules/cjs/loader.js:945:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10) at Module.load (internal/modules/cjs/loader.js:798:32) at Function.Module._load (internal/modules/cjs/loader.js:711:12) at Module.require (internal/modules/cjs/loader.js:838:19)
hi @eschirtz can you do the following:
- remove dependency of @tensorflow/tfjs in package.json. tfjs-node will install @tensorflow/tfjs with corresponding version.
- use the exact version of @tensorflow/tfjs-node (remove
^before the version number). Deletenode_modules,yarn.lockandpackage-lock.json, then install dependencies. - if it's still not working, can you list what inside
.../node_modules/@tensorflow/tfjs-node/depsand.../node_modules/@tensorflow/tfjs-node/lib?
@Korochan17 which version of @tensorflow/tfjs-node are you using and what's your OS?
@kangyizhang It appears to have worked! I'm going to mess around with it a little more, but I think removing the @tensorflow/tfjs in package.json cleared things up.
Thanks for your help :)
@kangyizhang i m using tfjsnode v1.2.12 the latest version as i added it through yarn add @tensorflow/tfjs-node my os is win32
hi @Korochan17 I think you mean 1.2.11 cause 1.2.12 is not released yet. can you do the following:
- Delete
node_modules/@tensorflow/tfjs-node, then reinstall it and paste the logs - if it's still not working, can you list what is inside
.../node_modules/@tensorflow/tfjs-node/depsand.../node_modules/@tensorflow/tfjs-node/lib? - if you folk @tensorflow/tfjs repo, go to folder tfjs-node, run
yarnandyarn test, paste the logs here.
hi @kangyizhang
i did everything but the problem is that there is still no such file tfjs_binding.node in node_modules/@tensorflow/tfjs-node/lib/napi-v4
when i installed it with npm i @tensorflow/tfjs-node, i got this
@tensorflow/[email protected] install E:\AI\tensorflow\node_modules@tensorflow\tfjs-node node scripts/install.js
CPU-windows-1.2.11.zip
- Downloading libtensorflow [==============================] 3570674/bps 100% 0.0s [==============================] 636153/bps 100% 0.0s
- Building TensorFlow Node.js bindings
node-pre-gyp install failed with error: Error: Command failed: node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v4/1.2.11/CPU-windows-1.2.11.zip
node-pre-gyp WARN Pre-built binaries not found for @tensorflow/[email protected] and [email protected] (node-v72 ABI, unknown) (falling back to source compile with node-gyp)
gyp ERR! build error
gyp ERR! stack Error:
E:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exefailed with exit code: 1 gyp ERR! stack at ChildProcess.onExit (C:\Users\koroa\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:196:23) gyp ERR! stack at ChildProcess.emit (events.js:210:5) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12) gyp ERR! System Windows_NT 10.0.18362 gyp ERR! command "E:\Program Files (x86)\nodejs\node.exe" "C:\Users\koroa\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "build" "--fallback-to-build" "--module=E:\AI\tensorflow\node_modules\@tensorflow\tfjs-node\lib\napi-v4\tfjs_binding.node" "--module_name=tfjs_binding" "--module_path=E:\AI\tensorflow\node_modules\@tensorflow\tfjs-node\lib\napi-v4" "--napi_version=5" "--node_abi_napi=napi" "--napi_build_version=4" "--node_napi_label=napi-v4" gyp ERR! cwd E:\AI\tensorflow\node_modules@tensorflow\tfjs-node gyp ERR! node -v v12.11.1 gyp ERR! node-gyp -v v5.0.3 gyp ERR! not ok node-pre-gyp ERR! build error node-pre-gyp ERR! stack Error: Failed to execute 'E:\Program Files (x86)\nodejs\node.exe C:\Users\koroa\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build --module=E:\AI\tensorflow\node_modules@tensorflow\tfjs-node\lib\napi-v4\tfjs_binding.node --module_name=tfjs_binding --module_path=E:\AI\tensorflow\node_modules@tensorflow\tfjs-node\lib\napi-v4 --napi_version=5 --node_abi_napi=napi --napi_build_version=4 --node_napi_label=napi-v4' (1) node-pre-gyp ERR! stack at ChildProcess.(E:\AI\tensorflow\node_modules\node-pre-gyp\lib\util\compile.js:83:29) node-pre-gyp ERR! stack at ChildProcess.emit (events.js:210:5) node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:1021:16) node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
node-pre-gyp ERR! System Windows_NT 10.0.18362 node-pre-gyp ERR! command "E:\Program Files (x86)\nodejs\node.exe" "E:\AI\tensorflow\node_modules\node-pre-gyp\bin\node-pre-gyp" "install" "--fallback-to-build" node-pre-gyp ERR! cwd E:\AI\tensorflow\node_modules@tensorflow\tfjs-node node-pre-gyp ERR! node -v v12.11.1 node-pre-gyp ERR! node-pre-gyp -v v0.13.0 node-pre-gyp ERR! not ok
npm WARN saveError ENOENT: no such file or directory, open 'E:\AI\tensorflow\package.json' npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN enoent ENOENT: no such file or directory, open 'E:\AI\tensorflow\package.json' npm WARN tensorflow No description npm WARN tensorflow No repository field. npm WARN tensorflow No README data npm WARN tensorflow No license field.
- @tensorflow/[email protected] added 86 packages from 85 contributors and audited 150 packages in 104.667s found 0 vulnerabilities
there are maybe some problems with node-pre-gyp and gyp
@Korochan17 can you install windows-build-tools (https://github.com/tensorflow/tfjs/blob/master/tfjs-node/WINDOWS_TROUBLESHOOTING.md#msbuildexe-exceptions) and try again?
@kangyizhang thanks a lot it was solved but another error
node_internal/modules/cjs/loader.js:992 return process.dlopen(module, path.toNamespacedPath(filename)); Error:...@tensorflow\tfjs-node\lib\napi-v4\tfjs_binding.node is not a valid Win32 application.
@Korochan17 it seems like the node.js kernel is trying to load the addon as Win32 application. Can you try to run node -p "process.arch"? Your machine should be Windows 64-bit x86 and your node process should be 64 bit as well.