nodejs-mobile / prebuild-for-nodejs-mobile

CLI tool to compile node.js native modules for mobile
MIT License
17 stars 1 forks source link

Fails to build the bcrypt package (probably because of node-pre-gyp) #1

Open ghost opened 1 year ago

ghost commented 1 year ago

https://github.com/kelektiv/node.bcrypt.js

gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp

This is probably due to node-pre-gyp

It builds successfully outside of prebuild-for-nodejs-mobile


ANDROID_NDK_HOME=/home/user/opt/android/ndk/ npx prebuild-for-nodejs-mobile android-arm64 --sdk22
Exited with code 1
gyp info it worked if it ends with ok
gyp info using node-gyp@0.3.1
gyp info using node@16.17.0 | linux | x64
(node:225175) [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 /usr/bin/python2
gyp info spawn args [
gyp info spawn args   '/home/user/.cache/npm-cache/_npx/ef19bf872be79af2/node_modules/nodejs-mobile-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make-android',
gyp info spawn args   '-I',
gyp info spawn args   '/home/user/workspaces/aproject/src/node.bcrypt.js/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/user/.cache/npm-cache/_npx/ef19bf872be79af2/node_modules/nodejs-mobile-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/user/.cache/npm-cache/_npx/ef19bf872be79af2/node_modules/nodejs-mobile-react-native/android/libnode/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/home/user/.cache/npm-cache/_npx/ef19bf872be79af2/node_modules/nodejs-mobile-react-native/android/libnode',
gyp info spawn args   '-Dnode_gyp_dir=/home/user/.cache/npm-cache/_npx/ef19bf872be79af2/node_modules/nodejs-mobile-gyp',
gyp info spawn args   '-Dnode_lib_file=/home/user/.cache/npm-cache/_npx/ef19bf872be79af2/node_modules/nodejs-mobile-react-native/android/libnode/$(Configuration)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/home/user/workspaces/aproject/src/node.bcrypt.js',
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 ]
gyp: Undefined variable module_name in binding.gyp 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 (/home/user/.cache/npm-cache/_npx/ef19bf872be79af2/node_modules/nodejs-mobile-gyp/lib/configure.js:334:16)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Linux 6.2.11-300.fc38.x86_64
gyp ERR! command "/home/user/.local/share/volta/tools/image/node/16.17.0/bin/node" "/home/user/.cache/npm-cache/_npx/ef19bf872be79af2/node_modules/nodejs-mobile-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/user/workspaces/aproject/src/node.bcrypt.js
gyp ERR! node -v v16.17.0
gyp ERR! node-gyp -v v0.3.1
gyp ERR! not ok 
ghost commented 1 year ago

I said it successfuly built, but in the case I meant without being built for android.

Here's what i did to get it to build for android at least.

This is probably similar to what prebuild-for-nodjs-mobile does (at least in the android case)

#!/bin/sh
export ANDROID_NDK_PATH=/home/user/opt/android/ndk/25.2.9519653
# probably not needed
export PATH=$PATH:/usr/sbin:$ANDROID_NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/

toolchain_target_arch=aarch64
node_target_arch=arm64

android_api_level=22
export CC=$ANDROID_NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/${toolchain_target_arch}-linux-android${android_api_level}-clang
export CXX=$ANDROID_NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/${toolchain_target_arch}-linux-android${android_api_level}-clang++
export LINK=$ANDROID_NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/${toolchain_target_arch}-linux-android${android_api_level}-clang++
export AR=$ANDROID_NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar

export npm_config_nodedir=/path/to/projectwithlibnode/node_modules/capacitor-nodejs/android/libnode
export npm_config_arch=${node_target_arch}
export node_config_plaform=android
# maybe this isn't required?
export node_config_format=make-android

./node_modules/.bin/node-pre-gyp -v rebuild