7

I cannot install '@tensorflow/tfjs-node'

I installed it using 'npm install @tensorflow/tfjs-node' but the installations fails. I tried installing 'node-pre-gyp' globally, with and without root permissions but no success. I run on node v12.9.0.


> fsevents@1.2.9 install /Users/username/Documents/Development/AI/Tensorflow/node_modules/fsevents
> node install

node-pre-gyp WARN Using needle for node-pre-gyp https download 
[fsevents] Success: "/Users/username/Documents/Development/AI/Tensorflow/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64/fse.node" is installed via remote

> @tensorflow/tfjs-node@1.2.9 install /Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node
> node scripts/install.js

CPU-darwin-1.2.9.tar.gz
* Downloading libtensorflow
[==============================] 10422374/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.9/CPU-darwin-1.2.9.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for @tensorflow/tfjs-node@1.2.9 and node@12.9.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp) 
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.

gyp: No Xcode or CLT version detected!
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:344:16)
gyp ERR! stack     at ChildProcess.emit (events.js:209:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 19.0.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node/lib/napi-v4/tfjs_binding.node" "--module_name=tfjs_binding" "--module_path=/Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node/lib/napi-v4" "--napi_version=4" "--node_abi_napi=napi" "--napi_build_version=4" "--node_napi_label=napi-v4"
gyp ERR! cwd /Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node
gyp ERR! node -v v12.9.0
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 '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node/lib/napi-v4/tfjs_binding.node --module_name=tfjs_binding --module_path=/Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node/lib/napi-v4 --napi_version=4 --node_abi_napi=napi --napi_build_version=4 --node_napi_label=napi-v4' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/username/Documents/Development/AI/Tensorflow/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:209:13)
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 Darwin 19.0.0
node-pre-gyp ERR! command "/usr/local/bin/node" "/Users/username/Documents/Development/AI/Tensorflow/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/username/Documents/Development/AI/Tensorflow/node_modules/@tensorflow/tfjs-node
node-pre-gyp ERR! node -v v12.9.0
node-pre-gyp ERR! node-pre-gyp -v v0.13.0
node-pre-gyp ERR! not ok 


> nodemon@1.19.2 postinstall /Users/username/Documents/Development/AI/Tensorflow/node_modules/nodemon
> node bin/postinstall || exit 0

npm WARN tensorflow@1.0.0 No description
npm WARN tensorflow@1.0.0 No repository field.

added 362 packages from 202 contributors and audited 2419 packages in 11.642s
found 0 vulnerabilities

node-pre-gyp failes to install and 'CPU-darwin-1.2.9.tar.gz' no longer seems to exist, so I get an 404 error.

Also this question if probably somewhat of a duplicate to this question: Cannot import @tensorflow/tfjs-node in nodejs

EDIT: Tried to downgrade to @tensorflow/tfjs-node@1.2.8, but the error is still there:

CPU-darwin-1.2.8.tar.gz
* Downloading libtensorflow
[==============================] 10642013/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.8/tfjs_binding-v1.2.8-node-v72-darwin-x64.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for @tensorflow/tfjs-node@1.2.8 and node@12.9.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp) 
XENOTnet
  • 101
  • 1
  • 6

5 Answers5

4

node-pre-gyp is a nice tool in that it can download precompiled binaries for you which can save a lot of time. The problem is that there still has to be binaries built for your exact version of nodejs.

In your case it seems like none are available (the below line is in the logfile you posted).

node-pre-gyp WARN Tried to download(404): https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v4/1.2.9/CPU-darwin-1.2.9.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for @tensorflow/tfjs-node@1.2.9 and node@12.9.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp) 

If we look at the url it tried to download however there seems to be a file available for version 1.2.8 (you can get a list of available files at https://storage.googleapis.com/tf-builds/).

So either you downgrade @tensorflow/tfjs-node to 1.2.8 and tries that or you check out the instructions for node-gyp to actually get it to build stuff on your machine (which is probably the best thing long term).

Karl-Johan Sjögren
  • 16,544
  • 7
  • 59
  • 68
  • I tried using 'npm i @tensorflow/tfjs-node@1.2.8', but still it seems to get to a 404 error: ```* 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.8/tfjs_binding-v1.2.8-node-v72-darwin-x64.tar.gz``` I'm sorry about to formatting, I'm new to stackoverflow and didn't know where else to put the error. – XENOTnet Sep 07 '19 at 16:26
  • Yeah that seems to be a second dependency that it needs which afais isn't available prebuilt for any version (at least not in that repo). So your best bet after all seems to be to install the required stuff for [node-gyp](https://github.com/nodejs/node-gyp#on-macos) (ie xcode commandline tools). – Karl-Johan Sjögren Sep 07 '19 at 17:30
  • xcode commandline tools are installed, but it won't work anyways. And I can't wrap my head around how to build the stuff on my machine. – XENOTnet Sep 08 '19 at 12:33
  • i am having the same issue i will appreciate help on this : node-pre-gyp install failed with error: Error: Command failed: node-pre-gyp install --fallback-to-build – Richard Aguirre Sep 15 '19 at 16:09
  • Solved whith this npm install --production windows-build-tools – Richard Aguirre Sep 15 '19 at 19:44
3

I solved the same problem with this command

npm install --production windows-build-tools

Richard Aguirre
  • 543
  • 6
  • 14
0

I had the same issue on MacOS 10.15 when installing 1.5.2.

CPU-darwin-1.5.2.tar.gz
* Downloading libtensorflow
[==============================] 15666967/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-v5/1.5.2/CPU-darwin-1.5.2.tar.gz
node-pre-gyp WARN Pre-built binaries not found for @tensorflow/tfjs-node@1.5.2 and node@12.15.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp)

https://www.npmjs.com/package/@tensorflow/tfjs-node#windows--mac-os-x-requires-python-27

You have to be using python 2.7 when attempting the install. If you aren't you will get a similar error to that you posted, I was in a python3 venv and thus got this error; falling back to 2.7 solved the problem.

0

Use node-v12.18.3 for solving this error

You can download this version by using this link

https://nodejs.org/en/blog/release/v12.18.3/
0

Try adjusting your node version slightly with nvm or your favourite node version manager to make sure your napi version matches what google has precompiled.

I was having trouble with node-pre-gyp with node v12.16.0 on my server (node v12.21.0 on my windows machine worked great!). I spent hours debugging thinking that the slight version difference couldn't be an issue, but it turns out 12.16.0 and 12.21.0 use different napi versions, and Google only precompiles tfjs for particular napi versions.

Here's a table of which node versions use which napi versions: https://nodejs.org/api/n-api.html#n_api_node_api_version_matrix

Here's the list of precompiled builds available: https://storage.googleapis.com/tf-builds/

The fix: Pick a version of node that uses a napi that you can find in Google's precompiled builds. In my case, I found I needed pre-built-binary/napi-v7/3.9.0/CPU-linux-3.9.0.tar.gz (from the error message) for @tensorflow/tfjs-node@3.9.0, so I checked the node API table to find that meant I wanted node version v12.19.0.

For the OP's question, it's trying to grab pre-built-binary/napi-v4/1.2.9/CPU-darwin-1.2.9.tar.gz, which does appear to built now (as of late 2021).

ArtHare
  • 1,798
  • 20
  • 22