nodejs / node-gyp

Node.js native addon build tool
MIT License
9.94k stars 1.79k forks source link

[ERROR] TypeError: cannot use a string pattern on a bytes-like object #2121

Closed loretoparisi closed 4 years ago

loretoparisi commented 4 years ago

I'm getting this error with latest nodehun nodehun@3.0.1 while building on macOS 10.14.5 (Darwin 18.6.0)

mbploreto:webservice loretoparisi$ node --version
v12.13.1
mbploreto:webservice loretoparisi$ npm --version
6.12.1
mbploreto:webservice loretoparisi$ node-gyp --version
v6.0.1
  CC(target) Release/obj.target/nothing/../node-addon-api/src/nothing.o
  LIBTOOL-STATIC Release/nothing.a
Traceback (most recent call last):
  File "./gyp-mac-tool", line 611, in <module>
    sys.exit(main(sys.argv[1:]))
  File "./gyp-mac-tool", line 30, in main
    exit_code = executor.Dispatch(args)
  File "./gyp-mac-tool", line 45, in Dispatch
    return getattr(self, method)(*args[1:])
  File "./gyp-mac-tool", line 248, in ExecFilterLibtool
    if not libtool_re.match(line) and not libtool_re5.match(line):
TypeError: cannot use a string pattern on a bytes-like object
make: *** [Release/nothing.a] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 18.6.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/loretoparisi/Documents/Projects/node_modules/nodehun
gyp ERR! node -v v12.13.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok 
npm WARN musixmatch-ai-console@6.2.6-20200511 No repository field.
npm WARN musixmatch-ai-console@6.2.6-20200511 No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nodehun@3.0.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the nodehun@3.0.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

It seems to me that this is related to node-gyp rather than this module itself.

loretoparisi commented 4 years ago

[UPDATE] According to this SF question this issue maybe related when using Python 3.x instead of Python 2.7 when on macOS If this is the case, how to make node-gyp to use the old version of python. When on macOS we now have python 3.7.7 with brew by defaults, so my workaround was:

brew install python@2 (if for some crazy reason it was removed, very unlikely
brew link python@2

or to force the latter brew link --overwrite --dry-run python@2 and then you should get both python (python2) and python3 installed.

It's important to notice the since node-gpy still requires python to be Python2.7 you need also to specify the right library path, then you may want to alias it in .bash_profile:

function __py3 {
    export PYTHONPATH=/usr/local/lib/python3.7/site-packages/
}
function __py2 {
    export PYTHONPATH=/Library/Python/2.7/site-packages
}
alias py3='__py3'
alias py2='__py2'

My two cent. Why node-gyp does not upgrade to Python3?

cclauss commented 4 years ago

You have two different node-gyp installed... v6.0.1 and v5.0.5 (see the error log).

Please upgrade gyp ERR! node-gyp -v v5.0.5 to https://github.com/nodejs/node-gyp/releases

loretoparisi commented 4 years ago

@cclauss thanks, I can only see

ip-192-168-1-168:Projects loretoparisi$ which node-gyp
/usr/local/bin/node-gyp
ip-192-168-1-168:Projects loretoparisi$ node-gyp --version
v6.0.1
cclauss commented 4 years ago

Please look through your log above:

gyp ERR! node -v v12.13.1
gyp ERR! node-gyp -v v5.0.5
loretoparisi commented 4 years ago

@cclauss thank you. So if I do a locate node-gyp I cannot find the offender version v5.0.5 under path like

/usr/local/n/versions/node/
/usr/local/lib/node_modules/npm/node_modules/node-gyp
/usr/local/Cellar/node/
/Users/loretoparisi/.node-gyp/

etc.

cclauss commented 4 years ago

/Users/loretoparisi/Documents/Projects/node_modules/node-gyp/gyp ?

loretoparisi commented 4 years ago

while I have all these (not sure why actually!)

/Users/loretoparisi/.node-gyp/
10.0.0/  10.1.0/  10.15.3/ 11.1.0/  6.9.4/   8.11.1/  8.11.2/  8.12.0/  8.9.1/   8.9.4/   9.11.1/  

I think I have found it here

 /usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp --version
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):

since it crashes and it is linked to Python2. Do you think is the right one? Under setup.py I can see

ip-192-168-1-168:pose-animator loretoparisi$ cat /usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/setup.py 
#!/usr/bin/env python

# Copyright (c) 2009 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from setuptools import setup

setup(
  name='gyp',
  version='0.1',
  description='Generate Your Projects',
  author='Chromium Authors',
  author_email='chromium-dev@googlegroups.com',
  url='http://code.google.com/p/gyp',
  package_dir = {'': 'pylib'},
  packages=['gyp', 'gyp.generator'],
  entry_points = {'console_scripts': ['gyp=gyp:script_main'] }
)
Wulf commented 4 years ago

hey @loretoparisi :)

I ran into this issue myself -- turns out I just needed to updated NPM itself (which has node-gyp as a dependency)

npm i -g npm
tekumara commented 4 years ago

Thanks @wulf, npm i -g npm fixed this for me! (I'm using node v11.15.0 on Darwin 19.6.0)

loretoparisi commented 4 years ago

@Wulf great, thank you! in fact it worked with node v12.16.1, npm v6.13.4, node-gyp v6.0.1. Closing then.