brain.js: Npm i brain.js || node-gyp error

When installing Brain.js using npm I got this error

Node version 18.18.2 Python version 3.12.0

npm WARN deprecated @npmcli/move-file@2.0.1: This functionality has been moved to @npmcli/fs npm ERR! code 1 npm ERR! path C:\Users\dell\Desktop\Node\GeminiNode\node_modules\gl npm ERR! command failed npm ERR! command C:\Windows\system32\cmd.exe /d /s /c prebuild-install || node-gyp rebuild npm ERR! prebuild-install warn install No prebuilt binaries found (target=18.18.2 runtime=node arch=x64 libc= platform=win32) npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@9.4.1 npm ERR! gyp info using node@18.18.2 | win32 | x64 npm ERR! gyp info find Python using Python version 3.12.2 found at “C:\Users\dell\AppData\Local\Programs\Python\Python312\python.exe” npm ERR! gyp info find VS using VS2022 (17.9.34622.214) found at: npm ERR! gyp info find VS “C:\Program Files\Microsoft Visual Studio\2022\Community” npm ERR! gyp info find VS run with --verbose for detailed information npm ERR! gyp info spawn C:\Users\dell\AppData\Local\Programs\Python\Python312\python.exe npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args ‘C:\Users\dell\Desktop\Node\GeminiNode\node_modules\node-gyp\gyp\gyp_main.py’, npm ERR! gyp info spawn args ‘binding.gyp’, npm ERR! gyp info spawn args ‘-f’, npm ERR! gyp info spawn args ‘msvs’, npm ERR! gyp info spawn args ‘-I’, npm ERR! gyp info spawn args ‘C:\Users\dell\Desktop\Node\GeminiNode\node_modules\gl\build\config.gypi’, npm ERR! gyp info spawn args ‘-I’, npm ERR! gyp info spawn args ‘C:\Users\dell\Desktop\Node\GeminiNode\node_modules\node-gyp\addon.gypi’, npm ERR! gyp info spawn args ‘-I’, npm ERR! gyp info spawn args ‘C:\Users\dell\AppData\Local\node-gyp\Cache\18.18.2\include\node\common.gypi’, npm ERR! gyp info spawn args ‘-Dlibrary=shared_library’, npm ERR! gyp info spawn args ‘-Dvisibility=default’, npm ERR! gyp info spawn args ‘-Dnode_root_dir=C:\Users\dell\AppData\Local\node-gyp\Cache\18.18.2’, npm ERR! gyp info spawn args ‘-Dnode_gyp_dir=C:\Users\dell\Desktop\Node\GeminiNode\node_modules\node-gyp’, npm ERR! gyp info spawn args ‘-Dnode_lib_file=C:\\Users\\dell\\AppData\\Local\\node-gyp\\Cache\\18.18.2\\<(target_arch)\\node.lib’, npm ERR! gyp info spawn args ‘-Dmodule_root_dir=C:\Users\dell\Desktop\Node\GeminiNode\node_modules\gl’, npm ERR! gyp info spawn args ‘-Dnode_engine=v8’, npm ERR! gyp info spawn args ‘–depth=.’, npm ERR! gyp info spawn args ‘–no-parallel’, npm ERR! gyp info spawn args ‘–generator-output’, npm ERR! gyp info spawn args ‘C:\Users\dell\Desktop\Node\GeminiNode\node_modules\gl\build’, npm ERR! gyp info spawn args ‘-Goutput_dir=.’ npm ERR! gyp info spawn args ] npm ERR! Traceback (most recent call last): npm ERR! File “C:\Users\dell\Desktop\Node\GeminiNode\node_modules\node-gyp\gyp\gyp_main.py”, line 42, in <module> npm ERR! import gyp # noqa: E402 npm ERR! ^^^^^^^^^^ npm ERR! File “C:\Users\dell\Desktop\Node\GeminiNode\node_modules\node-gyp\gyp\pylib\gyp_init_.py”, line 9, in <module> npm ERR! import gyp.input npm ERR! File “C:\Users\dell\Desktop\Node\GeminiNode\node_modules\node-gyp\gyp\pylib\gyp\input.py”, line 19, in <module> npm ERR! from distutils.version import StrictVersion npm ERR! ModuleNotFoundError: No module named ‘distutils’ npm ERR! gyp ERR! configure error npm ERR! gyp ERR! stack Error: gyp failed with exit code: 1 npm ERR! gyp ERR! stack at ChildProcess.onCpExit (C:\Users\dell\Desktop\Node\GeminiNode\node_modules\node-gyp\lib\configure.js:325:16) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:517:28) npm ERR! gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:292:12) npm ERR! gyp ERR! System Windows_NT 10.0.22621 npm ERR! gyp ERR! command “C:\Program Files\nodejs\node.exe” “C:\Users\dell\Desktop\Node\GeminiNode\node_modules\node-gyp\bin\node-gyp.js” “rebuild”
npm ERR! gyp ERR! cwd C:\Users\dell\Desktop\Node\GeminiNode\node_modules\gl npm ERR! gyp ERR! node -v v18.18.2 npm ERR! gyp ERR! node-gyp -v v9.4.1 npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in: C:\Users\dell\AppData\Local\npm-cache_logs\2024-03-11T03_00_33_620Z-debug-0.log

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 8
  • Comments: 17 (5 by maintainers)

Most upvoted comments

I’m having this problem as well. Please fix it! Running brain.js through a python virtual environment shouldn’t be the solution.

Hey! I find a solution:

Reproduce:

  1. npm install brain.js
  2. Same error.

Solution and how I find it:

  • Firstly tried to install distutils. I read distutils was not found because it was removed at 3.12.
  • Then, I read on my local (Turkish) forum (you can read it clicking by this text) it says it is removed from Python 3.12 and I should use this command instead: pip install setuptools
  • I went back to my project folder (main node.js project folder) opened a PowerShell as Administrator and simply pasted command above.

It worked!

I have same issue, ubuntu 24.04 node 20 installed using nvm tried upgrading npm to v11

npm error gyp ERR! node -v v20.17.0 npm error gyp ERR! node-gyp -v v9.4.1

to solve this, do following:

python3 -m venv .venv             
source .venv/bin/activate
pip install setuptools
npm i brain.js

Could you possibly add that to the readme?