Search code examples
node-gyp

Node gyp ERR - invalid mode: 'rU' while trying to load binding.gyp


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


Solution

  • 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