skip to Main Content

Importing

// Frontend - Vue.js
const tfn = require('@tensorflow/tfjs-node')

then running

npm install --save @tensorflow/tfjs-node

gets me followed error:

npm ERR! node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1093:16)
npm ERR! node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
npm ERR! node-pre-gyp ERR! System Windows_NT 10.0.22000
npm ERR! node-pre-gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\Name\Desktop\Team\my-app\node_modules\@mapbox\node-pre-gyp\bin\node-pre-gyp" "install" "--fallback-to-build"
npm ERR! node-pre-gyp ERR! cwd C:UsersNameDesktopTeammy-appnode_modules@tensorflowtfjs-node
npm ERR! node-pre-gyp ERR! node -v v16.17.0
npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.9
npm ERR! node-pre-gyp ERR! not ok

What I already found, but didn’t help: 1 , 2

Using:
[email protected] / Python 3.10.6 / nodev16.17.0 /
node-pre-gyp v1.0.9 / Windows 11 / Visual Studio Code

I need tfjs-node to load my local tensorflow model

const tfn = require("@tensorflow/tfjs-node");
const handler = tfn.io.fileSystem("./path/to/your/model.json");
const model = await tf.loadLayersModel(handler);

After installing npm i @tensorflow/[email protected] (Suggestion from @Vladimir Mandic):

98% after emitting CopyPlugin

WARNING  Compiled with 4 warnings                                                                                                                                                                 15:06:11
 warning  in ./node_modules/@tensorflow/tfjs-node/dist/index.js

Critical dependency: the request of a dependency is an expression
warning  in ./node_modules/@tensorflow/tfjs-node/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js

Module not found: Error: Can't resolve 'node-gyp' in 'C:UsersNameDesktopTeammy-appnode_modules@tensorflowtfjs-nodenode_modules@mapboxnode-pre-gyplibutil'
warning  in ./node_modules/@tensorflow/tfjs-node/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js

Module not found: Error: Can't resolve 'npm' in 'C:UsersNameDesktopTeammy-appnode_modules@tensorflowtfjs-nodenode_modules@mapboxnode-pre-gyplibutil'  
warning  in ./node_modules/@tensorflow/tfjs-node/node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html

Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <!doctype html>
| <html>
| <head>

 @ ./node_modules/@tensorflow/tfjs-node/node_modules/@mapbox/node-pre-gyp/lib sync ^./.*$
 @ ./node_modules/@tensorflow/tfjs-node/node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
 @ ./node_modules/@tensorflow/tfjs-node/dist/index.js
 @ ./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/@vue/cli-plugin-eslint/node_modules/eslint-loader??ref--14-0!./src/components/PublishCode.js?vue&type=script&lang=js&
 @ ./src/components/PublishCode.js?vue&type=script&lang=js&
 @ ./src/components/Publish.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://172.16.7.172:80&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

2

Answers


  1. installer for @tensorflow/tfjs-node only tries build
    if it cannot find and download prebuild binaries for a given platform
    (and build process is anything but simple)

    in your case, you’re on windows x64 and using nodejs v16, so it should be ok

    but…pre-build binaries for that platform for tfjs 3.19.0 are not correctly published
    (you can check https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v8/3.19.0/CPU-windows-3.19.0.zip and see the error directly)

    tfjs team will fix it soon

    but for the time being, i suggest to use tfjs-node 3.18.0 instead
    (you can check https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v8/3.18.0/CPU-windows-3.18.0.zip and see its fine)

    Login or Signup to reply.
  2. try installing a different version of tfjs
    ( ps these worked for me )

    "@tensorflow-models/posenet": "^2.2.2",
    "@tensorflow/tfjs": "^3.20.0",
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search