【问题标题】:How to use ffi-napi in Google Cloud Functions at Node v10如何在 Node v10 的 Google Cloud Functions 中使用 ffi-napi
【发布时间】:2020-06-12 20:57:40
【问题描述】:

我在 Google Cloud Function (Node v10) 中遇到本机模块依赖项(特别是 IBM MQ for js)的问题,并且在任何地方都没有找到我需要的信息,所以我打开了这个问题并回答了自己让其他人以后可以找到它。

它在 Node v8 引擎中运行良好,但现在已弃用。在将引擎升级到 v10 并碰撞一些包(遵循关于我的依赖项的所有迁移指南)之后,ffi-napi 包在yarn install 期间抛出异常,如下所示:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: ...s status = napi_get_instance_data(env, &d);
                        ^~~~~~~~~~~~~~~~~~~~~~
../src/ffi.cc:11:24: note: suggested alternative: 'napi_new_instance'
   napi_status status = napi_get_instance_data(env, &d);
                        ^~~~~~~~~~~~~~~~~~~~~~
                        napi_new_instance
../src/ffi.cc: In function 'Napi::Object BindingHook(Napi::Env, Napi::Object)':
../src/ffi.cc:347:24: error: 'napi_set_instance_data' was not declared in this scope
   napi_status status = napi_set_instance_data(
                        ^~~~~~~~~~~~~~~~~~~~~~
../src/ffi.cc:347:24: note: suggested alternative: 'napi_new_instance'
   napi_status status = napi_set_instance_data(
                        ^~~~~~~~~~~~~~~~~~~~~~
                        napi_new_instance
In file included from ../src/ffi.cc:3:0:
../src/ffi.h: At global scope:
../src/ffi.h:148:19: warning: mangled name for 'Napi::TypedArray FFI::WrapPointer(Napi::Env, T*, size_t) [with T = char*() throw ()]' will change in C++17 because the exception specification is part of a function type [-Wnoexcept-type]
 inline TypedArray WrapPointer(Env env, T* ptr, size_t length = 0) {
                   ^~~~~~~~~~~
../src/ffi.h:148:19: warning: mangled name for 'Napi::TypedArray FFI::WrapPointer(Napi::Env, T*, size_t) [with T = void*(void*, const char*) throw ()]' will change in C++17 because the exception specification is part of a function type [-Wnoexcept-type]
../src/ffi.h:148:19: warning: mangled name for 'Napi::TypedArray FFI::WrapPointer(Napi::Env, T*, size_t) [with T = int(void*) throw ()]' will change in C++17 because the exception specification is part of a function type [-Wnoexcept-type]
../src/ffi.h:148:19: warning: mangled name for 'Napi::TypedArray FFI::WrapPointer(Napi::Env, T*, size_t) [with T = void*(const char*, int) throw ()]' will change in C++17 because the exception specification is part of a function type [-Wnoexcept-type]
make: *** [Release/obj.target/ffi_bindings/src/ffi.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:191:23)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 5.3.0-1020-gcp
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /workspace/node_modules/ffi-napi
gyp ERR! node -v v10.19.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ffi-napi@3.0.1 install: `node-gyp-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ffi-napi@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:
npm ERR!     /builder/home/.npm/_logs/2020-06-12T17_47_25_766Z-debug.log; Error ID: c4475859

它在本地(OSX Catalina 节点 10.21)和 Docker(在基于 alpine 的节点 10 和 12 主要标签中测试)都可以正常工作。

【问题讨论】:

    标签: node.js google-cloud-platform google-cloud-functions ibm-mq n-api


    【解决方案1】:

    TLDR:尚不支持。


    我刚刚发现在Node v10.20(v10.20.0 中添加了napi_get_instance_data)中引入了一些 IBM MQ 包依赖项(特别是 ffi-napi)所需的本机 API,但 Google Cloud Functions 是基于 @987654324 @。

    到目前为止,我发现的唯一解决方法是使用 Yarn Resolutions 或自定义分叉将 ffi-napi 降级为 v2.4.7。没有关于 Cloud Functions 引擎中 Node v10.20 的预期版本的公开信息。

    【讨论】:

    • 我已在 Google Cloud 问题跟踪器中为此创建了一个功能请求,并会在收到回复时更新此答案。 issuetracker.google.com/issues/158862265
    • Google 回答了这个问题,但没有提供更多细节,而是遵循 Node 12 功能请求。所以我要结束这个问题,因为不知道当前 v10 运行时是否会支持它。
    猜你喜欢
    • 1970-01-01
    • 2021-06-26
    • 1970-01-01
    • 2021-12-26
    • 2020-06-30
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 2020-08-06
    相关资源
    最近更新 更多