brain.js icon indicating copy to clipboard operation
brain.js copied to clipboard

Npm i brain.js || node-gyp error

Open Ramank200 opened this issue 1 year ago • 17 comments

When installing Brain.js using npm I got this error

Node version 18.18.2 Python version 3.12.0

npm WARN deprecated @npmcli/[email protected]: 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 [email protected] npm ERR! gyp info using [email protected] | 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 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 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 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

Ramank200 avatar Mar 11 '24 03:03 Ramank200

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!

atailh4n avatar Jun 07 '24 18:06 atailh4n

Could you possibly add that to the readme?

robertleeplummerjr avatar Jul 10 '24 19:07 robertleeplummerjr

to solve this, do following:

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

DasRed avatar Jul 22 '24 14:07 DasRed

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

AdonisAIOfficial avatar Aug 02 '24 10:08 AdonisAIOfficial

From the log...

Python version 3.12.0 npm ERR! gyp info using [email protected]

Python 3.12 REQUIRES node-gyp@10 or greater because it NEEDS setuptools.

cclauss avatar Oct 16 '24 14:10 cclauss

I'm getting this error too, and I haven't been able to install brain.js through the suggested methods above (running a python virtual env, installing setuptools, etc).

I also tried installing node-gyp globally so I'm at v10.2.0. Also tried installing node-gyp locally before running npm i brain.js. But it seems when installing brain.js it doesn't make use of either the global or local installed node-gyp.

Does anyone have any suggestions for how to make sure brain.js uses the v10 of node-gyp when running npm i brain.js? Or any other pointers? Thanks for the help, much appreciated!

tmhglnd avatar Oct 19 '24 09:10 tmhglnd

I also tried installing node-gyp globally so I'm at v10.2.0.

Does your error log say node-gyp v10.2.0?

cclauss avatar Oct 19 '24 14:10 cclauss

I also tried installing node-gyp globally so I'm at v10.2.0.

Does your error log say node-gyp v10.2.0?

No, it seems it keeps using v9 (npm error gyp ERR! node-gyp -v v9.4.1) and I'm not sure how to make it so it does use v10. I tried different things like installing node-gyp globally and locally, but that doesn't seem to make a difference.

tmhglnd avatar Oct 19 '24 18:10 tmhglnd

Edit or create the node-gyp entry in package.json and/or package-lock.json?

cclauss avatar Oct 19 '24 20:10 cclauss

Edit or create the node-gyp entry in package.json and/or package-lock.json?

Nothing to do there sadly, both files have: "node-gyp": "^10.2.0".

tmhglnd avatar Oct 19 '24 21:10 tmhglnd

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

ilgianlu avatar Jan 10 '25 09:01 ilgianlu

Python >= v3.12 requires node-gyp >= v10.

  • https://github.com/nodejs/node-gyp/releases

cclauss avatar Jan 10 '25 09:01 cclauss

Python >= v3.12 requires node-gyp >= v10.

  • https://github.com/nodejs/node-gyp/releases

We know Python >= 3.12 needs node-gyp >= 10.

node-gyp is called within the gl dependency as a transient dependency from gpu.js. This is why it does not use the correct version installed globally or locally.

The solution for me was to modify the package.json at the root of my project so the child dependencies of brain.js uses the right gl version. I added at the end of my package.json:

"overrides": {

    "brain.js": {

      "gpu.js": {

        "gl": "^8.1.6"

      }

    }

  }

This is a temporary fix and PRs like this one inside the incriminated dependency (gpu.js) are still waiting to be merged.

thomasgainant avatar Apr 21 '25 11:04 thomasgainant

Python >= v3.12 requires node-gyp >= v10.

  • https://github.com/nodejs/node-gyp/releases

We know Python >= 3.12 needs node-gyp >= 10.

node-gyp is called within the gl dependency as a transient dependency from gpu.js. This is why it does not use the correct version installed globally or locally.

The solution for me was to modify the package.json at the root of my project so the child dependencies of brain.js uses the right gl version. I added at the end of my package.json:

"overrides": {

    "brain.js": {

      "gpu.js": {

        "gl": "^8.1.6"

      }

    }

  }

This is a temporary fix and PRs like this one inside the incriminated dependency (gpu.js) are still waiting to be merged.

The pnpm equivilent for this would be

  "pnpm": {
    "overrides": {
      "gl": "^8.1.6"
    }
  },

Thought I'd add this here just in case.

decipher-cs avatar Jun 04 '25 10:06 decipher-cs

Hi, I've opened PR about this, updated README. Use distutils.

atailh4n avatar Jun 04 '25 11:06 atailh4n

I'm getting this error too, and I haven't been able to install brain.js through the suggested methods above (running a python virtual env, installing setuptools, etc).

I also tried installing node-gyp globally so I'm at v10.2.0. Also tried installing node-gyp locally before running npm i brain.js. But it seems when installing brain.js it doesn't make use of either the global or local installed node-gyp.

Does anyone have any suggestions for how to make sure brain.js uses the v10 of node-gyp when running npm i brain.js? Or any other pointers? Thanks for the help, much appreciated!

I've run into this issue as well. What helped in my case was installing some components from the Visual Studio 2022 Installer — not the full IDE, but specifically the C++ build tools (or related development libraries).

Additionally, if brain.js isn't picking up your globally or locally installed node-gyp (v10 in your case), you might want to force an override. One way to do this is by modifying the package.json to explicitly specify the node-gyp version you want during the install process.

Unfortunately, I'm currently on mobile so I can't paste the exact code snippets right now, but I’ll include a detailed explanation and working example in the README and update the PR shortly.

Hope that helps for now!

atailh4n avatar Jun 04 '25 11:06 atailh4n

OK, I've done README update. I hope it merges.

atailh4n avatar Jun 04 '25 15:06 atailh4n