question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tfjs-node "Illegal instruction: 4" error on macOS Monterey (M1)

See original GitHub issue

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS 12.1 (Monterey), 2020 MacBook Air M1
  • TensorFlow.js installed from (npm or script link): npm
  • TensorFlow.js version: “@tensorflow/tfjs”: “^3.16.0”, “@tensorflow/tfjs-node”: “^3.16.0”

Describe the problem In an empty project, installing and requiring @tensorflow/tfjs-node results in an “Illegal instruction: 4” error thrown.

Provide the exact sequence of commands / steps that you executed before running into the problem

  • Create an empty project (npm init)
  • yarn add @tensorflow/tfjs-node in project root
  • create an index.js file and add const tf = require('@tensorflow/tfjs-node') at the top of the file
  • node index.js in project root
  • observe error “Illegal instruction: 4” thrown

As reported in the closed https://github.com/tensorflow/tfjs/issues/4514 ticket, tfjs-node doesn’t appear to work with macOS Monterey. Is there any way to make it work?

Would appreciate any tips, cheers!

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:14

github_iconTop GitHub Comments

2reactions
pyu10055commented, Jul 13, 2022

Hi @MikeOBarometer @Caundy I have tried the setup Mike mentioned, it is also working for me. There are couple caveats you need to pay attention to:

  1. Make sure you are starting your terminal without rosetta. (Which make sure the arch is in arm64)
  2. use nvm to install node with arm64 binary.
  3. install tfjs-node after that.

This way, your node environment arch matches with tfjs-node binding and TF download. And x86-64 arch that enabled by rosetta would not work with tensorflow (the illegal instruction 4 error), even though all archs match. Please let me know if this would work for you.

2reactions
MikeOBarometercommented, Jun 14, 2022

Strange! Let me know if I can provide any other system info if it helps. Here’s my versions + arch

$ node -v && npm -v && npm info @tensorflow/tfjs-node version && uname -m
v16.15.1
8.11.0
3.18.0
arm64
Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the "Illegal Instruction: 4" error and why does "
I get Illegal Instruction: 4 errors with binaries compiled with GCC 4.7.2 under Mac OS X 10.8.2 ("Mountain Lion"), when those binaries are...
Read more >
Fixing "Illegal instruction 4 error in macOS terminal when ...
Hi, I am currently trying to install deep labcut on my macbook (has an M1 chip and is running on Big sur version...
Read more >
tensorflow-metal | Apple Developer Forums
I was trying to train a tf model with on my M1 macbook pro then got a InvalidArgumentError, as follows: InvalidArgumentError: Cannot assign...
Read more >
@tensorflow/tfjs-node - npm
This repository provides native TensorFlow execution in backend JavaScript applications under the Node.js runtime, accelerated by the ...
Read more >
How to - zsh: illegal hardware instruction (TensorFlow m1 Mac)
in this video i show you exactly How to fix - zsh: illegal hardware instruction ( M1 Mac Tensorflow Error ) - this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found