tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

Error installing on M2 Mac (15.4.1)

Open tpiros opened this issue 7 months ago • 8 comments

I thought that my issue was related to https://github.com/tensorflow/tfjs/issues/8497 but my path doesn't have spaces in it.

I followed the instructions on the npm page:

  • I have a supported version of Python (3.13.2)
  • I have arm64 build
  • xcode-select --install is done (at least it returns xcode-select: note: Command line tools are already installed.

Node version is v22.14.0.

npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated [email protected]: This package is no longer supported.
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: This package is no longer supported.
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated [email protected]: This package is no longer supported.
npm error code 1
npm error path /Users/tpiros/development/ai/sample-training/node_modules/@tensorflow/tfjs-node
npm error command failed
npm error command sh -c node scripts/install.js
npm error CPU-darwin-4.22.0.tar.gz
npm error https://storage.googleapis.com/tf-builds/libtensorflow_r2_7_darwin_arm64_cpu.tar.gz
npm error node-pre-gyp install failed with error: Error: Command failed: node-pre-gyp install --fallback-to-build
npm error node-pre-gyp info it worked if it ends with ok
npm error node-pre-gyp info using [email protected]
npm error node-pre-gyp info using [email protected] | darwin | arm64
npm error node-pre-gyp info check checked for "/Users/tpiros/development/ai/sample-training/node_modules/@tensorflow/tfjs-node/lib/napi-v8/tfjs_binding.node" (not found)
npm error node-pre-gyp http GET https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v8/4.22.0/CPU-darwin-4.22.0.tar.gz
npm error node-pre-gyp ERR! install response status 404 Not Found on https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v8/4.22.0/CPU-darwin-4.22.0.tar.gz 
npm error node-pre-gyp WARN Pre-built binaries not installable for @tensorflow/[email protected] and [email protected] (node-v127 ABI, unknown) (falling back to source compile with node-gyp) 
npm error node-pre-gyp WARN Hit error response status 404 Not Found on https://storage.googleapis.com/tf-builds/pre-built-binary/napi-v8/4.22.0/CPU-darwin-4.22.0.tar.gz 
npm error gyp info it worked if it ends with ok
npm error gyp info using [email protected]
npm error gyp info using [email protected] | darwin | arm64
npm error gyp info ok 
npm error gyp info it worked if it ends with ok
npm error gyp info using [email protected]
npm error gyp info using [email protected] | darwin | arm64
npm error gyp info find Python using Python version 3.13.2 found at "/Library/Frameworks/Python.framework/Versions/3.13/bin/python3"
npm error gyp info spawn /Library/Frameworks/Python.framework/Versions/3.13/bin/python3
npm error gyp info spawn args [
npm error gyp info spawn args '/Users/tpiros/.npm-global/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm error gyp info spawn args 'binding.gyp',
npm error gyp info spawn args '-f',
npm error gyp info spawn args 'make',
npm error gyp info spawn args '-I',
npm error gyp info spawn args '/Users/tpiros/development/ai/sample-training/node_modules/@tensorflow/tfjs-node/build/config.gypi',
npm error gyp info spawn args '-I',
npm error gyp info spawn args '/Users/tpiros/.npm-global/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm error gyp info spawn args '-I',
npm error gyp info spawn args '/Users/tpiros/Library/Caches/node-gyp/22.14.0/include/node/common.gypi',
npm error gyp info spawn args '-Dlibrary=shared_library',
npm error gyp info spawn args '-Dvisibility=default',
npm error gyp info spawn args '-Dnode_root_dir=/Users/tpiros/Library/Caches/node-gyp/22.14.0',
npm error gyp info spawn args '-Dnode_gyp_dir=/Users/tpiros/.npm-global/lib/node_modules/npm/node_modules/node-gyp',
npm error gyp info spawn args '-Dnode_lib_file=/Users/tpiros/Library/Caches/node-gyp/22.14.0/<(target_arch)/node.lib',
npm error gyp info spawn args '-Dmodule_root_dir=/Users/tpiros/development/ai/sample-training/node_modules/@tensorflow/tfjs-node',
npm error gyp info spawn args '-Dnode_engine=v8',
npm error gyp info spawn args '--depth=.',
npm error gyp info spawn args '--no-parallel',
npm error gyp info spawn args '--generator-output',
npm error gyp info spawn args 'build',
npm error gyp info spawn args '-Goutput_dir=.'
npm error gyp info spawn args ]
npm error <string>:38: SyntaxWarning: invalid escape sequence '\$'
npm error gyp info ok 
npm error gyp info it worked if it ends with ok
npm error gyp info using [email protected]
npm error gyp info using [email protected] | darwin | arm64
npm error gyp info spawn make
npm error gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm error In file included from ../binding/tfjs_backend.cc:18:
npm error ../binding/tfjs_backend.h:22:10: fatal error: 'memory' file not found
npm error    22 | #include <memory>
npm error       |          ^~~~~~~~
npm error 1 error generated.
npm error make: *** [Release/obj.target/tfjs_binding/binding/tfjs_backend.o] Error 1
npm error gyp ERR! build error 
npm error gyp ERR! stack Error: `make` failed with exit code: 2
npm error gyp ERR! stack at ChildProcess.<anonymous> (/Users/tpiros/.npm-global/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:209:23)
npm error gyp ERR! System Darwin 24.4.0
npm error gyp ERR! command "/usr/local/bin/node" "/Users/tpiros/.npm-global/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/Users/tpiros/development/ai/sample-training/node_modules/@tensorflow/tfjs-node/lib/napi-v8/tfjs_binding.node" "--module_name=tfjs_binding" "--module_path=/Users/tpiros/development/ai/sample-training/node_modules/@tensorflow/tfjs-node/lib/napi-v8" "--napi_version=10" "--node_abi_napi=napi" "--napi_build_version=8" "--node_napi_label=napi-v8"
npm error gyp ERR! cwd /Users/tpiros/development/ai/sample-training/node_modules/@tensorflow/tfjs-node
npm error gyp ERR! node -v v22.14.0
npm error gyp ERR! node-gyp -v v10.1.0
npm error gyp ERR! not ok 
npm error node-pre-gyp ERR! build error 
npm error node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /Users/tpiros/.npm-global/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/tpiros/development/ai/sample-training/node_modules/@tensorflow/tfjs-node/lib/napi-v8/tfjs_binding.node --module_name=tfjs_binding --module_path=/Users/tpiros/development/ai/sample-training/node_modules/@tensorflow/tfjs-node/lib/napi-v8 --napi_version=10 --node_abi_napi=napi --napi_build_version=8 --node_napi_label=napi-v8' (1)
npm error node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/tpiros/development/ai/sample-training/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
npm error node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:518:28)
npm error node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1101:16)
npm error node-pre-gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:304:5)
npm error node-pre-gyp ERR! System Darwin 24.4.0
npm error node-pre-gyp ERR! command "/usr/local/bin/node" "/Users/tpiros/development/ai/sample-training/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
npm error node-pre-gyp ERR! cwd /Users/tpiros/development/ai/sample-training/node_modules/@tensorflow/tfjs-node
npm error node-pre-gyp ERR! node -v v22.14.0
npm error node-pre-gyp ERR! node-pre-gyp -v v1.0.9
npm error node-pre-gyp ERR! not ok
npm error * Downloading libtensorflow
npm error
npm error * Building TensorFlow Node.js bindings
npm error A complete log of this run can be found in: /Users/tpiros/.npm/_logs/2025-05-10T15_54_24_637Z-debug-0.log

tpiros avatar May 10 '25 15:05 tpiros

Hi @tpiros ,

If the issue isn't with the tfjs-node installation path, it might be an Xcode configuration problem. Can you try configuring Xcode by running: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer. After that, delete the node_modules folder and package-lock.json file, clear the npm cache with npm cache clean --force, and then reinstall the tfjs-node dependency using npm install @tensorflow/tfjs-node.

Let me know if it helps.

Thank You!!

shmishra99 avatar May 13 '25 06:05 shmishra99

Installing the entire Xcode from the App Store did do the job, maybe it's me but I did not see this as a requirement in the docs.

tpiros avatar May 13 '25 07:05 tpiros

I'm glad to hear your issue has been resolved. The tfjs-node documentation mentions the requirement of Xcode installation from command line. Feel free to close the issue if your issue has been resolved. Thank You!!

shmishra99 avatar May 13 '25 08:05 shmishra99

The documentation states to run xcode-select --install which is used to install the Xcode Command Line Tools, not the entire Xcode App.

tpiros avatar May 13 '25 09:05 tpiros

Installing Xcode from the command line should be sufficient to install tfjs-node. Could you try running xcode-select --install and then setting the active developer path to /Applications/Xcode.app/Contents/Developer? Please let me know if that resolves the issue for you. Thank You!!

shmishra99 avatar May 15 '25 07:05 shmishra99

The only thing that resolved the issue for me was to do a full blown Xcode install. I can no longer run the command you suggested because I have Xcode up and running on my machine.

tpiros avatar May 15 '25 07:05 tpiros

Sure, we have tested this issue with the Mac M1 chip. I'll try to test it on the M2 chip and update the document accordingly. I'll keep you posted regarding this issue. Thank You!!

shmishra99 avatar Jun 02 '25 07:06 shmishra99

I had to install python's setuptools before I could install tfjs-node.

cdavie-artium avatar Jul 17 '25 00:07 cdavie-artium