Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need to upgrade node-gyp #1116

Open
soroushm opened this issue Nov 26, 2023 · 6 comments
Open

need to upgrade node-gyp #1116

soroushm opened this issue Nov 26, 2023 · 6 comments

Comments

@soroushm
Copy link

distutils has been removed in Python v3.12. we need to upgrade version of node-gyp (to v10+)

› Traceback (most recent call last):
  File "xxxxx\node_modules\@electron\rebuild\node_modules\node-gyp\gyp\gyp_main.py", line 42, in <module>
  import gyp  # noqa: E402
  ^^^^^^^^^^
  File "xxxxxx\node_modules\@electron\rebuild\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 9, in <mod…
  import gyp.input
  File "xxxxx\node_modules\@electron\rebuild\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 19, in <modul…
  from distutils.version import StrictVersion
  ModuleNotFoundError: No module named 'distutils'
  Error: `gyp` failed with exit code: 1
      at ChildProcess.onCpExit (xxxx\node_modules\@electron\rebuild\n…

An unhandled rejection has occurred inside Forge:
Error: node-gyp failed to rebuild 'xxxxx2\node_modules\robotjs'
at ChildProcess.<anonymous> (xxxxx\node_modules\@electron\rebuild\lib\module-type\node-gyp\node-gyp.js:118:24)
    at ChildProcess.emit (node:events:537:28)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)
@si458
Copy link

si458 commented Dec 8, 2023

can confirm same issue, a temp fix is to include the latest node-gyp as a devDependency in YOUR package.json
npm install node-gyp --save-dev should install 10.0.1

joedevivo added a commit to joedevivo/vscode-circuitpython that referenced this issue Dec 30, 2023
@aquacode
Copy link

Hi,
I'm struggling to get electron-rebuild to work due to node-gyp version and Python version (as others reported above).

I've tried the so-called temp fix by adding the devDependency in my package.json to the latest node-gyp but it's not getting used by electron-rebuild.

Is there any other known workaround for this issue?

@tarekis
Copy link

tarekis commented Mar 1, 2024

As references in nodejs/node-gyp#2869 (comment), node-gyp v10+ solves this error; distutils was removed from python 3.12 as mentioned here, which causes this error.

A way to fix this is to add an overrides to your package.json.

In my case (using pnpm) on the highest level in my package.json:

  "pnpm": {
    "overrides": {
      "node-gyp": "^10.0.0"
    }
  },

Do this according to how your package manager handles overrides.

If your package manager does not update correctly, check your lock file and confirm @electron/rebuild has the depency node-gyp set to some 10+ version, at the time of writing 10.0.1. If this is the case, try deleting your lockfile and have it re-generate with e.g. pnpm i or equivalent in your package manager.

For reference, with pnpm my relevant lockfile info looks like this:
  /@electron/rebuild@3.6.0:
    resolution: {integrity: sha512-zF4x3QupRU3uNGaP5X1wjpmcjfw1H87kyqZ00Tc3HvriV+4gmOGuvQjGNkrJuXdsApssdNyVwLsy+TaeTGGcVw==}
    engines: {node: '>=12.13.0'}
    hasBin: true
    dependencies:
      '@malept/cross-spawn-promise': 2.0.0
      chalk: 4.1.2
      debug: 4.3.4
      detect-libc: 2.0.2
      fs-extra: 10.1.0
      got: 11.8.6
      node-abi: 3.56.0
      node-api-version: 0.2.0
      node-gyp: 10.0.1
      ora: 5.4.1
      read-binary-file-arch: 1.0.6
      semver: 7.6.0
      tar: 6.2.0
      yargs: 17.7.2
    transitivePeerDependencies:
      - supports-color
    dev: true

EDIT:
I have been fiddling around with this a while before I came to this conclusion which is not enough to get it running, so the above will not work.
I have edited the file node_modules\@electron\rebuild\lib\module-type\node-gyp\worker.js:29 to remove the promisify since v10 of node-gyp changes it's internals to return promises natively.

That is an integral part of the solution. I guess I'll see if I can cook up a PR to this project to resolve this issue.

@verhovsky
Copy link

overrides didn't work for me, but this did:

pip install setuptools

or possibly

python3 -m pip install --break-system-packages setuptools

@Komodood
Copy link

can confirm same issue, a temp fix is to include the latest node-gyp as a devDependency in YOUR package.json npm install node-gyp --save-dev should install 10.0.1

thx for temp fix actually

@buuhvprojects
Copy link

buuhvprojects commented May 5, 2024

pip install setuptools

Thanks, this solutions worked for me on windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants