если не libtool_re.match (строка) и не libtool_re5.match (строка): TypeError: нельзя использовать строковый шаблон в байтовоподобном объекте - PullRequest
0 голосов
/ 25 октября 2018

Я пытался вызвать код C / C ++ из проекта узла, и когда я делаю npm install, чтобы создать его, я получаю странную ошибку типа

Я использую Anaconda с Python 3.7 в качестве глобального Python.У меня также установлен Python 2.7

python installed

Так что я сделал, чтобы запустить

npm config set python /usr/local/bin/python

, но я все еще получаю эту ошибку

npm install                                                       ✔ master

> app@0.0.0 install /Users/aa/binding
> node-gyp rebuild

  CC(target) Release/obj.target/nothing/node_modules/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 28, in main
    exit_code = executor.Dispatch(args)
  File "./gyp-mac-tool", line 43, in Dispatch
    return getattr(self, method)(*args[1:])
  File "./gyp-mac-tool", line 246, 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 (/Users/aa/anaconda/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Darwin 18.0.0
gyp ERR! command "/Users/abhimanyuaryan/anaconda/bin/node" "/Users/aa/anaconda/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/aa/binding
gyp ERR! node -v v8.11.3
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app@0.0.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app@0.0.0 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:
npm ERR!     /Users/aa/.npm/_logs/2018-10-25T10_13_17_726Z-debug.log

****** Мой исходный код: ******

binding.cpp

#include <napi.h>

using namespace Napi;

String Hello(const CallbackInfo& info) {
  return String::New(info.Env(), "world");
}

void Init(Env env, Object exports, Object module) {
  exports.Set("hello", Function::New(env, Hello));
}

NODE_API_MODULE(addon, Init)

binding.gyp

{
  "targets": [
    {
      "target_name": "native",
      "sources": [
        "binding.cpp"
      ],
      "include_dirs": [
        "<!@(node -p \"require('node-addon-api').include\")"
      ],
      "dependencies": [
        "<!(node -p \"require('node-addon-api').gyp\")"
      ],
      "cflags!": ["-fno-exceptions"],
      "cflags_cc!": ["-fno-exceptions"],
      "defines": ["NAPI_CPP_EXCEPTIONS"]
    }
  ]
}

package.json

{
  "name": "app",
  "version": "0.0.0",
  "private": true,
  "gypfile": true,
  "dependencies": {
    "node-addon-api": "^1.5.0"
  }
} 
...