101

Getting the following error when running yarn install

gyp/bin/node-gyp.js clean configure gyp info it worked if it ends with ok gyp info using [email protected] gyp info using [email protected] | darwin | arm64 gyp info find Python using Python version 3.11.0 found at \"/Library/Frameworks/Python.framework/Versions/3.11/bin/python3\" (node:28367) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only. (Use `node --trace-deprecation ...` to show where the warning was created) gyp info spawn /Library/Frameworks/Python.framework/Versions/3.11/bin/python3 gyp info spawn args [ gyp info spawn args '/Users/username/chegg-web/node_modules/node-gyp/gyp/gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make', gyp info spawn args '-I', gyp info spawn args '/Users/username/chegg-web/node_modules/@chegg/logger/node_modules/@newrelic/native-metrics/build/config.gypi', gyp info spawn args '-I', gyp info spawn args '/Users/username/chegg-web/node_modules/node-gyp/addon.gypi', gyp info spawn args '-I', gyp info spawn args '/Users/username/Library/Caches/node-gyp/16.18.1/include/node/common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/Users/username/Library/Caches/node-gyp/16.18.1', gyp info spawn args '-Dnode_gyp_dir=/Users/username/chegg-web/node_modules/node-gyp', gyp info spawn args '-Dnode_lib_file=/Users/username/Library/Caches/node-gyp/16.18.1/<(target_arch)/node.lib', gyp info spawn args '-Dmodule_root_dir=/Users/username/chegg-web/node_modules/@chegg/logger/node_modules/@newrelic/native-metrics', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'build', gyp info spawn args '-Goutput_dir=.' gyp info spawn args ] Traceback (most recent call last): File \"/Users/username/chegg-web/node_modules/node-gyp/gyp/gyp_main.py\", line 50, in <module> sys.exit(gyp.script_main()) ^^^^^^^^^^^^^^^^^ File \"/Users/username/chegg-web/node_modules/node-gyp/gyp/pylib/gyp/__init__.py\", line 554, in script_main return main(sys.argv[1:]) ^^^^^^^^^^^^^^^^^^ File \"/Users/username/chegg-web/node_modules/node-gyp/gyp/pylib/gyp/__init__.py\", line 547, in main return gyp_main(args) ^^^^^^^^^^^^^^ File \"/Users/username/chegg-web/node_modules/node-gyp/gyp/pylib/gyp/__init__.py\", line 520, in gyp_main [generator, flat_list, targets, data] = Load( ^^^^^ File \"/Users/username/chegg-web/node_modules/node-gyp/gyp/pylib/gyp/__init__.py\", line 136, in Load result = gyp.input.Load(build_files, default_variables, includes[:], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File \"/Users/username/chegg-web/node_modules/node-gyp/gyp/pylib/gyp/input.py\", line 2782, in Load LoadTargetBuildFile(build_file, data, aux_data, File \"/Users/username/chegg-web/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/username/chegg-web/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 gyp ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/Users/username/chegg-web/node_modules/node-gyp/lib/configure.js:351:16) gyp ERR! stack at ChildProcess.emit (node:events:513:28) gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12) gyp ERR! System Darwin 22.1.0 gyp ERR! command \"/Users/username/.nvm/versions/node/v16.18.1/bin/node\" \"/Users/username/chegg-web/node_modules/node-gyp/bin/node-gyp.js\" \"clean\" \"configure\" gyp ERR! cwd /Users/username/chegg-web/node_modules/@chegg/logger/node_modules/@newrelic/native-metrics gyp ERR! node -v v16.18.1 gyp ERR! node-gyp -v v5.1.1 gyp ERR! not ok Failed to execute native-metrics install: No pre-built artifacts for your OS/architecture." info This module is OPTIONAL, you can safely ignore this error 

Please advise what might be the cause? Running on Mac OS, M1, Ventura

10 Answers 10

102

I was facing this same error. I had python v3.11 and canvas v2.7.0 in my package.json.

Solution: All I did was downgrade my python version to v3.10 and the error disappeared. You can install it from here

Sign up to request clarification or add additional context in comments.

7 Comments

Great, that was a problem for me. Thx!
Downgrading is not a good solution
if using pyenv you can simply pyenv isntall 3.10.0 and pyenv global 3.10.0
After installing python 3.10 make sure to execute this command in your working directory eval "$(pyenv init --path)"
turns out it must be python 3.10.0, i was running 3.10.14 on my machine and it didn't work till i change it to 3.10.0...
|
46

This issue has been reported to node-gyp and was introduced on Python3.11. To solve it and keep using Python3.11 you can update your input.py file as the file 'rU' has been renamed to 'r' and that is why we see this error.

Location for the file: /Users/username/npm-versions/6.13.7/node_modules/node-gyp/gyp/pylib/gyp/input.py

Method to be updated: LoadOneBuildFile()

Method updated:

def LoadOneBuildFile(build_file_path, data, aux_data, includes, is_target, check): if build_file_path in data: return data[build_file_path] if os.path.exists(build_file_path): # Open the build file for read ('r') with universal-newlines mode ('U') # to make sure platform specific newlines ('\r\n' or '\r') are converted to '\n' # which otherwise will fail eval() if sys.platform == 'zos': # On z/OS, universal-newlines mode treats the file as an ascii file. But since # node-gyp produces ebcdic files, do not use that mode. build_file_contents = open(build_file_path, 'r').read() else: build_file_contents = open(build_file_path, 'r').read() # Here is the line you need to update. Instead of 'rU', update to only 'r' else: raise GypError("%s not found (cwd: %s)" % (build_file_path, os.getcwd())) 

5 Comments

For me, on Windows, the location of input.py was here C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\input.py
lifesaver <3 I have had the error for a few days and now its solved
the function code I found is completely different from what you've mentioned...it doesn't have a single 'rU' anywhere!
creating an python alias in .zshrc. export PATH="/usr/local/bin/python3:$PATH" alias python=python3. Still had install problem, simply recloning the repo fixed.
It's not a good idea to change the source code of other dependent package.
32

First Solution: If the Python version is needed for NPM's sake then try,..

npm config set python /path/to/executable/python

i.e. npm config set python /opt/homebrew/bin/python3.10

If the PYTHON environment variable is set to the path of a Python executable, then that version will be used, if it is a compatible version.

Second Solution: Set NODE_GYP_FORCE_PYTHON environment variable.

# file: $HOME/.bash_profile NODE_GYP_FORCE_PYTHON=/path/to/executable/python # Example: # export NODE_GYP_FORCE_PYTHON=/opt/homebrew/bin/python3.10 

2 Comments

brew install [email protected] and export NODE_GYP_FORCE_PYTHON=/opt/homebrew/bin/python3.10 solved it for me
I didn't want to configure Python in my global npm configuration so I created a local .npmrc file in my project and added the line python=/opt/homebrew/bin/python3.10. That worked.
13

If you're using prebuild, update it to v12.0.0.

node-gyp versions older than v8.0.0 don't work with Python 3.11. In my case, I was using an old version of the prebuild library which depended on node-gyp v6.0.1.

If you're using a library that doesn't have a newer version that depends on node-gyp 8+ then you can tell npm to use a more recent version of node-gyp by adding it to "dependencies": or "devDependencies": (whichever the library that depends on node-gyp is) and then adding it to "overrides": in your package.json file:

 "devDependencies": { "node-gyp": "9.4.0" }, "overrides": { "prebuild": { "node-gyp": "$node-gyp" } }, 

Replace "prebuild" above with whatever library depends on node-gyp.

The overrides attribute was added in npm 8.3, so this requires Node 16.

2 Comments

Thanks a lot! This should be correct answer. We shouldn't need to install py3.10 just to make a node package work...
Gold! Consider using npm why node-gyp to figure out what to override
9

I fixed that via the following steps:

  1. brew install [email protected]
  2. In the .zshrc I set export PYTHON=/opt/homebrew/bin/python3.10
  3. Don't forget to run source ~/.zshrc after you change your .zshrc

1 Comment

But my Mac is using Rosetta to switch to i386 arch, in order to run Node 14. So what can I do in that case?
6

If you don't mind removing python. I deleted Python from my system (Mac M1) and it fixed it. It is better to install python in virtual environments because one global installation can always have side effects on other projects. Refer to this article on how to delete python on a MacBook

If you want to keep your global python3 installation I recommend this answer above.

In summary, in your node_modules/node-gyp/gyp/pylib/gyp/input.py file there is such a line of code as below. (You can find this file by clicking on the final path printed in the error-trace in your terminal.)

Old code

 else: build_file_contents = open(build_file_path, 'rU').read() 

Since the 'rU' file read-mode is deprecated in python3 so you have to update that code to this. (Change rU to r)

New code

 else: build_file_contents = open(build_file_path, 'r').read() 

5 Comments

Who tf decided to remove a supported file mode on the open function in a minor release of Python?
Python isn't semver, I believe.
@WilliamEntriken the U flag has been deprecated since Python 3.3, so there was plenty of time to adapt. See docs.python.org/3/whatsnew/3.11.html#porting-to-python-3-11
Every time I update this file and run yarn install again it overwrites the file.
@Catfish, sorry about that. I seems that each time you run it, you have to make this fix again
5

I didn't want to deal with all the complexities nor downgrade default Python, the following workaround panned out:

  1. Install Miniconda
  2. conda create -n py310 python=3.10
  3. conda activate py310
  4. yarn

4 Comments

helped me with node-gyp on a M1 / ARM chip Macbook
At this moment node-gyp requires python 2.7 or 3.5+. For my older app conda create -n py2 python=2 worked.
I get an error: zsh: command not found: conda
@IgorGanapolsky You have to install Miniconda first, add it to the environment in order to have conda available in your environment.
5

I had the same issue when I installed python3.11. The solution is exporting the Python to be < 3.10.

Here is the command for Mac M1:

export PYTHON=/opt/homebrew/bin/python3.10 

Comments

4

This solution completely updates the node-gyp version and works regardless of your node version:

Linux Alpine (perhaps other distros):

find /usr/lib -type d -name "node-gyp" -exec sh -c 'cd "$(dirname "{}")" && npm i node-gyp@latest' \; 

Mac using nvm:

find ~/.nvm -type d -name "node-gyp" -exec sh -c 'cd "$(dirname "{}")" && npm i node-gyp@latest' \; 

basically find all the directories that have node-gyp for your current node installation and manually update the node-gyp version and all the nested dependencies.

On alpine linux I also got an error fatal error: vips/vips8: No such file or directory

So I had to install vips-dev

but when I rand apk add vips-dev I got an error:

ERROR: unable to select packages: libmount-2.38.1-r6: breaks: util-linux-dev-2.38.1-r7[libmount=2.38.1-r7] satisfies: glib-2.76.1-r1[so:libmount.so.1] 

to resolve this I ran

apk update apk add vips-dev 

And the vips-dev package installed this time

Now I can run yarn install with no errors!

Comments

0

Use this only once when install npm packages the first time.

npm install --python=/usr/bin/python2.7 

Change the python path if you are on windows or macos The next installs are going to work without passing the python path

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.