By Bartłomiej Szabłowski
Table of contents

If you happen to have an error of this kind:

Traceback (most recent call last):
File "/Users/bartzz/Desktop/project/xyz/vue/node_modules/node-gyp/gyp/gyp_main.py", line 50, in <module>
sys.exit(gyp.script_main())
^^^^^^^^^^^^^^^^^
File "/Users/bartzz/Desktop/project/xyz/vue/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 554, in script_main
return main(sys.argv[1:])
^^^^^^^^^^^^^^^^^^
File "/Users/bartzz/Desktop/project/xyz/vue/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 547, in main
return gyp_main(args)
^^^^^^^^^^^^^^
File "/Users/bartzz/Desktop/project/xyz/vue/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 520, in gyp_main
[generator, flat_list, targets, data] = Load(
^^^^^
File "/Users/bartzz/Desktop/project/xyz/vue/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 136, in Load
result = gyp.input.Load(build_files, default_variables, includes[:],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bartzz/Desktop/project/xyz/vue/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 2782, in Load
LoadTargetBuildFile(build_file, data, aux_data,
File "/Users/bartzz/Desktop/project/xyz/vue/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 391, in LoadTargetBuildFile
build_file_data = LoadOneBuildFile(build_file_path, data, aux_data,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bartzz/Desktop/project/xyz/vue/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 234, in LoadOneBuildFile
build_file_contents = open(build_file_path, 'rU').read()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid mode: 'rU' while trying to load binding.gyp

How to fix this error?

Then the easiest solution is to switch from Python 3.11 to Python 3.10.

  1. brew unlink python@3.11
  2. brew install python@3.10
  3. Close and reopen any terminals you might have
  4. Profit - node-gyp should now work.
Upgrade node-gyp-build to support python 3.11+ users · Issue #1087 · pact-foundation/pact-js
Software versions Please provide at least OS and version of pact-js OS: Mac OSX 12.6.1 Consumer Pact library: Pact JS@Latest Issue Checklist Please confirm the following: [*] I have upgraded to the...
Node gyp ERR - invalid mode: ‘rU’ while trying to load binding.gyp
Getting the following error when running yarn installgyp/bin/node-gyp.js clean configuregyp info it worked if it ends with okgyp info using node-gyp@5.1.1gyp info using node@16.18.1 | darwin | ...