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

Electron - Cannot find module napi-v4/tfjs_binding.node napi-v4 INSTEAD of napi-v5 #2640

Closed
Infinitay opened this issue Jan 4, 2020 · 2 comments

Comments

@Infinitay
Copy link

I am fairly new to node.js and Electron let alone tensorflow for js, so pardon my ignorance.

TensorFlow.js version

"@tensorflow/tfjs-node": "^1.5.1"

Browser version

I am using Electron and this is what is returned using process.versions

{
"node": "12.8.1",
"v8": "7.8.279.23-electron.0",
"uv": "1.30.1",
"zlib": "1.2.11",
"brotli": "1.0.7",
"ares": "1.15.0",
"modules": "75",
"nghttp2": "1.39.2",
"napi": "4",
"llhttp": "1.1.4",
"http_parser": "2.8.0",
"openssl": "1.1.0",
"icu": "64.2",
"unicode": "12.1",
"electron": "7.1.7",
"chrome": "78.0.3904.130"
}

It says I am using Node version 12, but I recently installed v13.5.0, so I don't know why it says v12.

Describe the problem or feature request

I am getting this error when I run my electron application: Uncaught Error: Cannot find module 'C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules\@tensorflow\tfjs-node\lib\napi-v4\tfjs_binding.node'. This started happening when I updated my old project that I have linked towards the end, both local dependencies and global. I also updated my node,js to the latest version for what it's worth.

So it seems to be trying to look for NAPI 4, but when I look into /node_modules/@tensorflow/tfjs-node/, there is a folder called build-tmp-napi-v5. Furthermore, and more importantly, when I go into /lib/, I find another folder labeled napi-v5, but no napi-v4. I was looking at other issues such as #2558 and #2341. From what I gathered, I think I need to downgrade my Node version and perhaps tfjs as well. I haven't tried yet, but I will in an hour or so of this post and post a reply.

npm install log

PS C:\Users\redacted\Documents\Code\NodeJS\Face-API> npm i

@tensorflow/tfjs-node@1.5.1 install C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules@tensorflow\tfjs-node
node scripts/install.js

CPU-windows-1.5.1.zip

  • Downloading libtensorflow
    [==============================] 72742801/bps 100% 0.0s
  • Building TensorFlow Node.js bindings

canvas@2.6.1 install C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules\canvas
node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
[canvas] Success: "C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules\canvas\build\Release\canvas.node" is installed via remote

core-js@3.6.1 postinstall C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules\core-js
node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:

https://opencollective.com/core-js
https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

electron@7.1.7 postinstall C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules\electron
node install.js

npm WARN face-api-testing@2.0.1 No repository field.

added 366 packages from 291 contributors and audited 792 packages in 27.51s

5 packages are looking for funding
run npm fund for details

found 0 vulnerabilities


Electron's logging output

[14832:0103/202922.885:INFO:CONSOLE(38)] "Platform browser has already been set. Overwriting the platform with [object Object].", source: C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules@tensorflow\tfjs-core\dist\environment.js (38)
[14832:0103/202923.119:VERBOSE1:CONSOLE(8157)] "Main._createAppUI: 27.920166015625ms", source: devtools://devtools/bundled/shell.js (8157)
[14832:0103/202923.166:VERBOSE1:CONSOLE(8157)] "Main._showAppUI: 17.798828125ms", source: devtools://devtools/bundled/shell.js (8157)
[14832:0103/202923.178:VERBOSE1:CONSOLE(8157)] "Main._initializeTarget: 11.094970703125ms", source: devtools://devtools/bundled/shell.js (8157)
[14832:0103/202923.315:VERBOSE1:CONSOLE(8157)] "Main._lateInitialization: 1.885009765625ms", source: devtools://devtools/bundled/shell.js (8157)
[14832:0103/202923.324:WARNING:CONSOLE(2419)] "%cElectron Security Warning (Insecure Content-Security-Policy) font-weight: bold; This renderer process has either no Content Security
Policy set or a policy with "unsafe-eval" enabled. This exposes users of
this app to unnecessary security risks.

For more information and help, consult
https://electronjs.org/docs/tutorial/security.
This warning will not show up
once the app is packaged.", source: electron/js2c/sandbox_bundle.js (2419)
node-pre-gyp info This Node instance does not support builds for N-API version 5
node-pre-gyp info This Node instance does not support builds for N-API version 5
[14832:0103/202923.405:INFO:CONSOLE(720)] "Uncaught Error: Cannot find module 'C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules@tensorflow\tfjs-node\lib\napi-v4\tfjs_binding.node'
Require stack:

  • C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules@tensorflow\tfjs-node\dist\index.js
  • C:\Users\redacted\Documents\Code\NodeJS\Face-API\face-rec.js
  • C:\Users\redacted\Documents\Code\NodeJS\Face-API\index.html", source: internal/modules/cjs/loader.js (720)
    [14832:0103/202923.503:INFO:CONSOLE(2854)] "%cElectron Security Warning (Insecure Content-Security-Policy) font-weight: bold; This renderer process has either no Content Security
    Policy set or a policy with "unsafe-eval" enabled. This exposes users of
    this app to unnecessary security risks.

For more information and help, consult
https://electronjs.org/docs/tutorial/security.
This warning will not show up
once the app is packaged.", source: electron/js2c/renderer_init.js (2854)


Chrome Console's Output When Running The App

Uncaught Error: Cannot find module 'C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules@tensorflow\tfjs-node\lib\napi-v4\tfjs_binding.node'
Require stack:

  • C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules@tensorflow\tfjs-node\dist\index.js
  • C:\Users\redacted\Documents\Code\NodeJS\Face-API\face-rec.js
  • C:\Users\redacted\Documents\Code\NodeJS\Face-API\index.html
    at Module._resolveFilename (internal/modules/cjs/loader.js:717:15)
    at Function../lib/common/reset-search-paths.ts.Module._resolveFilename (electron/js2c/renderer_init.js:925:16)
    at Module._load (internal/modules/cjs/loader.js:622:27)
    at Module._load (electron/js2c/asar.js:717:26)
    at Function.Module._load (electron/js2c/asar.js:717:26)
    at Module.require (internal/modules/cjs/loader.js:775:19)
    at require (internal/modules/cjs/helpers.js:68:18)
    at Object. (C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules@tensorflow\tfjs-node\dist\index.js:46:16)
    at Object. (C:\Users\redacted\Documents\Code\NodeJS\Face-API\node_modules@tensorflow\tfjs-node\dist\index.js:68:3)
    at Module._compile (internal/modules/cjs/loader.js:880:30)

Code to reproduce the bug / link to feature request

https://github.com/Infinitay/face-rec-photo-gallery/tree/testing-v2.0.2

@Infinitay
Copy link
Author

Infinitay commented Jan 4, 2020

I got around to coming back to this issue in an attempt to further troubleshoot it. I took a look once more at #2341 and realized that I also was using a different node.js version that Electron was (compiled with?). As of Jan 4th 2020, the latest Electron version is 7.1.7 and it is using Node version 12.8.1, so I installed Node v12.8.1 and tried everything once more. Voila! Problem solved.

If anyone else is having this issue, make sure your installed node.js version is the same as the version of Electron you're using!

EDIT: Although I'm curious, could this error be mitigated either by tfjs OR electron?

@fakob
Copy link

fakob commented Feb 12, 2020

@Infinitay
Thanks so much for your tip! I have been struggling for days to get it to work. Your solution was exactly it.

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