vladmandic / face-api

FaceAPI: AI-powered Face Detection & Rotation Tracking, Face Description & Recognition, Age & Gender & Emotion Prediction for Browser and NodeJS using TensorFlow/JS
https://vladmandic.github.io/face-api/demo/webcam.html
MIT License
824 stars 149 forks source link

Errors when attempting to use the library within an ElectonJS preload script #148

Closed mantzaris closed 1 year ago

mantzaris commented 1 year ago

I am using this library within an ElectronJS preload script.

Error: Cannot find module '@tensorflow/tfjs-node'
Require stack:
- /home/resort/Documents/repos/Tagasaurus/node_modules/@vladmandic/face-api/dist/face-api.node.js
- /home/resort/Documents/repos/Tagasaurus/preload.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
    at Function.i._resolveFilename (node:electron/js2c/renderer_init:33:1095)
    at Module._load (node:internal/modules/cjs/loader:785:27)
    at Function.c._load (node:electron/js2c/asar_bundle:5:13343)
    at Function.i._load (node:electron/js2c/renderer_init:33:356)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at /home/resort/Documents/repos/Tagasaurus/node_modules/@vladmandic/face-api/dist/face-api.node.js:7:1195
    at /home/resort/Documents/repos/Tagasaurus/node_modules/@vladmandic/face-api/dist/face-api.node.js:7:223
    at Object.<anonymous> (/home/resort/Documents/repos/Tagasaurus/node_modules/@vladmandic/face-api/dist/face-api.node.js:7:4316)
(anonymous) @ node:electron/js2c/renderer_init:73

I am attempting to use the library from the preload script via:

const faceapi = require('@vladmandic/face-api');

Is this behavior expected since I should not need tfjs-node since I am not using this within the nodejs context.

vladmandic commented 1 year ago

just the fact that you're using require means its within node context already as browser does not have require statements.
i suggest to take a look at https://github.com/vladmandic/human-electron for an example, its using my different library human instead of faceapi, but its the same tfjs backend and same concepts when it comes to electronjs loading/bundling