Face-api.js: node-js examples not compiling

Created on 3 Dec 2019  ·  16Comments  ·  Source: justadudewhohacks/face-api.js

To try and run the examples I do the following with a freshly cloned repo:

cd examples/examples-nodejs
npm i
tsc faceDetection.ts

I get the following error:

node_modules/@types/webgl2/index.d.ts:582:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'WebGL2RenderingContext' must be of type '{ new (): WebGL2RenderingContext; prototype: WebGL2RenderingContext; readonly ACTIVE_ATTRIBUTES: number; readonly ACTIVE_TEXTURE: number; ... 556 more ...; readonly WAIT_FAILED: number; }', but here has type '{ new (): WebGL2RenderingContext; prototype: WebGL2RenderingContext; readonly ACTIVE_ATTRIBUTES: number; readonly ACTIVE_TEXTURE: number; ... 557 more ...; readonly MAX_CLIENT_WAIT_TIMEOUT_WEBGL: number; }'.

582 declare var WebGL2RenderingContext: {
                ~~~~~~~~~~~~~~~~~~~~~~

  ../../../../../../usr/lib/node_modules/typescript/lib/lib.dom.d.ts:16485:13
    16485 declare var WebGL2RenderingContext: {
                      ~~~~~~~~~~~~~~~~~~~~~~
    'WebGL2RenderingContext' was also declared here.


Found 1 error.

I have the following:
tsc --version: 3.7.2
node --version: 12.13.0

I have tried adding skipLibCheck: true to tsconfig.json but it did not do any difference.

Do you have any idea why it is not working for node?

solution provided

Most helpful comment

The solution was to first run

npm i && npm run-script build

in the root directory before trying to run the examples.

All 16 comments

This command compile.
tsc --skipLibCheck faceDetection.ts
But then it doesn't work

error:

UnhandledPromiseRejectionWarning: TypeError: this.backend.register is not a function
    at Engine.registerTensor (/home/ff/nodejs/face-api.js/node_modules/@tensorflow/tfjs-core/dist/engine.js:468:30)

Please check out @russellwmy's answer in this issue #376. Make sure you are using the same typescript (take a look at the package.json of the examples folder) and tfjs-core version as face-api.js.

same error, I tried #376, seems different errors. not work. I just used the default package.json.
tsc --version Version 3.7.3
node --version v12.13.1

tsc --skipLibCheck faceDetection.ts
there is no error.
but when I run node faceDetection.js
(node:25928) UnhandledPromiseRejectionWarning: TypeError: this.backend.register is not a function
at Engine.registerTensor (E:\face\face-api.js\node_modules\@tensorflow\tfjs-core\dist\engine.js:468:30)
at new Tensor (E:\face\face-api.js\node_modules\@tensorflow\tfjs-core\dist\tensor.js:246:21)
at Function.Tensor.make (E:\face\face-api.js\node_modules\@tensorflow\tfjs-core\dist\tensor.js:261:16)
at makeTensor (E:\face\face-api.js\node_modules\@tensorflow\tfjs-core\dist\ops\tensor_ops.js:98:28)
at Object.tensor (E:\face\face-api.js\node_modules\@tensorflow\tfjs-core\dist\ops\tensor_ops.js:55:12)
at _loop_2 (E:\face\face-api.js\node_modules\@tensorflow\tfjs-core\dist\io\io_utils.js:219:36)
at Object.decodeWeights (E:\face\face-api.js\node_modules\@tensorflow\tfjs-core\dist\io\io_utils.js:223:9)
at E:\face\face-api.js\node_modules\@tensorflow\tfjs-core\dist\io\weights_loader.js:255:66
at Array.forEach ()
at E:\face\face-api.js\node_modules\@tensorflow\tfjs-core\dist\io\weights_loader.js:253:44
(node:25928) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:25928) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

got the reason. it seems the "npm i" in examples will get the tfjs 1.4.0 version, which is not compatible with face-api.js.

Thanks! Just to make this clear for anyone else, you can fix by removng the caret (^) in the package.json for @tensorflow/tfjs-node and getting version 1.2.3 specifically. For example in the examples folder changing package.json to:

{
  "author": "justadudewhohacks",
  "license": "MIT",
  "dependencies": {
    "@tensorflow/tfjs-node": "1.2.3",
    "canvas": "^2.5.0",
    "face-api.js": "../../"
  }
}

just cloned the repository, with
tsc --version: 3.7.3
node --version: v13.3.0

cd face-api.js/examples/examples-nodejs
npm i
ts-node  faceDetection.ts

gives:

faceDetection.ts:1:26 - error TS2307: Cannot find module 'face-api.js'.

1 import * as faceapi from 'face-api.js';

Same scenario, and same results as @sbocconi.

node --version: 12.4.0
tsc --version: 3.7.4

@sbocconi @imgh1010 What version of tfjs-node are you using? Did you change the version in package.json before installing with npm install as per my previous comment?

My package.json is as currently available in the repository:

{
  "author": "justadudewhohacks",
  "license": "MIT",
  "dependencies": {
    "@tensorflow/tfjs-node": "1.4.0",
    "canvas": "^2.6.0",
    "face-api.js": "../../"
  }
}

and the error does not depend on the version of tensorflow, but on the fact that face-api.js cannot be found.
I also tried with:

{
  "author": "justadudewhohacks",
  "license": "MIT",
  "dependencies": {
    "@tensorflow/tfjs-node": "1.4.0",
    "canvas": "^2.6.0",
    "face-api.js": "git+https://github.com/justadudewhohacks/face-api.js.git#master"
  }
}

but I get the same error, even after a npm install face-api.js

The solution was to first run

npm i && npm run-script build

in the root directory before trying to run the examples.

however,I found :
examples/examples-nodejs/package.json
{
"author": "justadudewhohacks",
"license": "MIT",
"dependencies": {
"face-api.js": "../../" # this will happen circulate create
}
}
will circulate create face-api.js fold, is usually or not? @justadudewhohacks

when I do "npm i" in console.

The solution was to first run

npm i && npm run-script build

in the root directory before trying to run the examples.

when I do “npm i && npm run-script build”,and I get:

@tensorflow/[email protected] install /home/dzy/Project/face-api.js/node_modules/@tensorflow/tfjs-node
node scripts/install.js

CPU-linux-1.7.0.tar.gz

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

[email protected] install /home/dzy/Project/face-api.js/node_modules/canvas
node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download
[canvas] Success: "/home/dzy/Project/face-api.js/node_modules/canvas/build/Release/canvas.node" is installed via remote
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 442 packages from 783 contributors and audited 1741 packages in 170.919s

10 packages are looking for funding
run npm fund for details

found 8 low severity vulnerabilities
run npm audit fix to fix them, or npm audit for details

face-api.[email protected] build /home/dzy/Project/face-api.js
rm -rf ./build && rm -rf ./dist && npm run rollup && npm run rollup-min && npm run tsc && npm run tsc-es6

face-api.[email protected] rollup /home/dzy/Project/face-api.js
rollup -c rollup.config.js

loaded rollup.config.js with warnings
(!) Unused external imports
default imported from external module 'path' but never used

src/index.ts → dist/face-api.js...
created dist/face-api.js in 10.3s

face-api.[email protected] rollup-min /home/dzy/Project/face-api.js
rollup -c rollup.config.js --environment minify:true

loaded rollup.config.js with warnings
(!) Unused external imports
default imported from external module 'path' but never used

src/index.ts → dist/face-api.min.js...
created dist/face-api.min.js in 14.5s

face-api.[email protected] tsc /home/dzy/Project/face-api.js
tsc

face-api.[email protected] tsc-es6 /home/dzy/Project/face-api.js
tsc --p tsconfig.es6.json
And tsc faceDetection.ts, get same error.

Worked fine for me:

  • npm install & npm run-script build (the remove commands for the directories fail on windows, remove them from package.json in the face-api.js\package.json file)
  • run npm install in examples-nodejs
  • running tsc faceDetection.ts fails with an error (duplicate librarydefinition WebGL2 or something)
  • instead tsc --skipLibCheck faceDetection.ts and things run fine.

@ronaldkuip I am also that add '--skipLibCheck' , but is fine?

ts-node faceDetection.ts should run in examples-nodejs directory.

Tsc -skipLibCheck.ts creates faceDetection.js

node faceDetection.js then runs fine too.

Van: homedawn notifications@github.com
Verzonden: woensdag 6 mei 2020 02:52
Aan: justadudewhohacks/face-api.js face-api.js@noreply.github.com
CC: ronaldkuip ronald.kuip@Live.nl; Mention mention@noreply.github.com
Onderwerp: Re: [justadudewhohacks/face-api.js] node-js examples not compiling (#491)

@ronaldkuiphttps://github.com/ronaldkuip I am also that add '--skipLibCheck' , but is fine?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/justadudewhohacks/face-api.js/issues/491#issuecomment-624383634, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACV4DRCPYR5R362D6IYE3JDRQCYDJANCNFSM4JUN6MOA.

Was this page helpful?
0 / 5 - 0 ratings