Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lib doesn't build when installed from NPM #7

Open
cakesoft-shashank opened this issue Dec 9, 2024 · 23 comments
Open

Lib doesn't build when installed from NPM #7

cakesoft-shashank opened this issue Dec 9, 2024 · 23 comments

Comments

@cakesoft-shashank
Copy link

cakesoft-shashank commented Dec 9, 2024

When trying to install the library via NPM, the build process fails with the following error

ld: unknown file type in '~/project/node_modules/rgb-lib/rgb-lib/bindings/c-ffi/target/debug/librgblibcffi.so'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Release/rgblib.node] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (~/project/node_modules/node-gyp/lib/build.js:203:23)
gyp ERR! stack     at ChildProcess.emit (node:events:517:28)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:292:12)
gyp ERR! System Darwin 24.2.0
gyp ERR! command "/Users/c58/.nvm/versions/node/v18.19.0/bin/node" "~/project/node_modules/rgb-lib/node_modules/.bin/node-gyp" "rebuild"
gyp ERR! cwd ~/project/node_modules/rgb-lib
gyp ERR! node -v v18.19.0
gyp ERR! node-gyp -v v9.4.1
gyp ERR! not ok
@zoedberg
Copy link
Contributor

Are you sure you're installing the library from NPM? From the logs it seems you are installing from the project. If you want to install the library from NPM please run npm install rgb-lib from outside the project's directory. If instead you want to install the library from the source code first be sure to have the submodule checked out by doing git submodule update --init and then, before running npm install, build the library as documented in the README, with npm run build or npm run docker-build.

@cakesoft-shashank
Copy link
Author

I tried to add the npm package using yarn add rgb-lib. While the library downloads successfully, the build process fails with the error mentioned above

@zoedberg
Copy link
Contributor

I tried to add the npm package using yarn add rgb-lib. While the library downloads successfully, the build process fails with the error mentioned above

Could you please clarify what do you mean for "the build process fails"? I've run yarn add rgb-lib && yarn install, then run a small script that imports and uses rgb-lib and I haven't encountered any issue. What OS are you using?

@cakesoft-shashank
Copy link
Author

I am on mac OS 15.2 and tried to install the package on node 18 and 20.

rgb.mov

@zoedberg
Copy link
Contributor

The error logs in the video are different from those you mentioned above. Are you sure the first time you weren't trying to do a local installation? Could you please post the correct error logs in text form?

I've tried to install it on a mac OS 12 (with node 20) and had no issues. Is your mac using an ARM chip? Is there anything else that's worth mentioning about your setup?

@cakesoft-shashank
Copy link
Author

Yes, I was trying to install the lib locally using npm. My Mac is ARM-based and running macOS 15.2. Are there any additional installation steps I need to follow? The lib works fine when added as a local dependency, but not when installed as an npm dependency.

@zoedberg
Copy link
Contributor

zoedberg commented Dec 30, 2024

Could you please post the correct error logs in text form?

Yes, I was trying to install the lib locally using npm. My Mac is ARM-based and running macOS 15.2. Are there any additional installation steps I need to follow? The lib works fine when added as a local dependency, but not when installed as an npm dependency.

No, there aren't additional steps. Have you tried installing the lib via npm instead of yarn?

@cakesoft-shashank
Copy link
Author

Yes I have tried that. Here is the full error log

npm error path /project/node_modules/rgb-lib
npm error command failed
npm error command sh -c node-gyp rebuild
npm error CXX(target) Release/obj.target/rgblib/swig_wrap.o
npm error   SOLINK_MODULE(target) Release/rgblib.node
npm error gyp info it worked if it ends with ok
npm error gyp info using [email protected]
npm error gyp info using [email protected] | darwin | arm64
npm error gyp info find Python using Python version 3.12.1 found at "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3"
npm error gyp info spawn /Library/Frameworks/Python.framework/Versions/3.12/bin/python3
npm error gyp info spawn args [
npm error gyp info spawn args   '/project/node_modules/node-gyp/gyp/gyp_main.py',
npm error gyp info spawn args   'binding.gyp',
npm error gyp info spawn args   '-f',
npm error gyp info spawn args   'make',
npm error gyp info spawn args   '-I',
npm error gyp info spawn args   '/project/node_modules/rgb-lib/build/config.gypi',
npm error gyp info spawn args   '-I',
npm error gyp info spawn args   '/project/node_modules/node-gyp/addon.gypi',
npm error gyp info spawn args   '-I',
npm error gyp info spawn args   '/Users/sha/Library/Caches/node-gyp/20.18.1/include/node/common.gypi',
npm error gyp info spawn args   '-Dlibrary=shared_library',
npm error gyp info spawn args   '-Dvisibility=default',
npm error gyp info spawn args   '-Dnode_root_dir=/Users/sha/Library/Caches/node-gyp/20.18.1',
npm error gyp info spawn args   '-Dnode_gyp_dir=/project/node_modules/node-gyp',
npm error gyp info spawn args   '-Dnode_lib_file=/Users/sha/Library/Caches/node-gyp/20.18.1/<(target_arch)/node.lib',
npm error gyp info spawn args   '-Dmodule_root_dir=/project/node_modules/rgb-lib',
npm error gyp info spawn args   '-Dnode_engine=v8',
npm error gyp info spawn args   '--depth=.',
npm error gyp info spawn args   '--no-parallel',
npm error gyp info spawn args   '--generator-output',
npm error gyp info spawn args   'build',
npm error gyp info spawn args   '-Goutput_dir=.'
npm error gyp info spawn args ]
npm error gyp info spawn make
npm error gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm error ../swig_wrap.cxx:1320:13: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
npm error  1320 |       res = sprintf(msg, "Tried to write read-only variable: %s.", buffer);
npm error       |             ^
npm error /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:274:1: note: 'sprintf' has been explicitly marked deprecated here
npm error   274 | __deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
npm error       | ^
npm error /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:218:48: note: expanded from macro '__deprecated_msg'
npm error   218 |         #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
npm error       |                                                       ^
npm error 1 warning generated.
npm error ld: unknown file type in '/project/node_modules/rgb-lib/rgb-lib/bindings/c-ffi/target/debug/librgblibcffi.so'
npm error clang++: error: linker command failed with exit code 1 (use -v to see invocation)
npm error make: *** [Release/rgblib.node] Error 1
npm error gyp ERR! build error 
npm error gyp ERR! stack Error: `make` failed with exit code: 2
npm error gyp ERR! stack     at ChildProcess.onExit (/project/node_modules/node-gyp/lib/build.js:203:23)
npm error gyp ERR! stack     at ChildProcess.emit (node:events:518:28)
npm error gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:293:12)
npm error gyp ERR! System Darwin 24.2.0
npm error gyp ERR! command "/Users/sha/.nvm/versions/node/v20.18.1/bin/node" "/project/node_modules/.bin/node-gyp" "rebuild"
npm error gyp ERR! cwd /project/node_modules/rgb-lib
npm error gyp ERR! node -v v20.18.1
npm error gyp ERR! node-gyp -v v9.4.1
npm error gyp ERR! not ok

Looks like librgblibcffi.so is not getting recognized on my system

@zoedberg
Copy link
Contributor

The lib works fine when added as a local dependency

Assuming you meant "built locally" instead of "added as a local", this is strange. Are you sure about this? Were you using the same machine (ARM-based Mac os)? If so, could you please clarify all the steps you did to build it, install it and check it works fine?

My guess is that the issue is related to the shared library (librgblibcffi.so) not being compiled for arm64, but this doesn't explain why the build is successful when the library gets built and installed locally.

@cakesoft-shashank
Copy link
Author

Yes, both are on the same machine. I followed the steps menthined here to build the library locally. After that, I added it as a local dependency in package.json using: "rgb-lib": "file:../rgb-lib-nodejs/rgb-lib"

@zoedberg
Copy link
Contributor

zoedberg commented Dec 30, 2024

Yes, both are on the same machine. I followed the steps menthined here to build the library locally. After that, I added it as a local dependency in package.json using: "rgb-lib": "file:../rgb-lib-nodejs/rgb-lib"

The README section you linked has instructions for both building locally and in docker, which ones did you follow? Please share the exact commands you gave

Also, have you then checked that the library actually works?

@cakesoft-shashank
Copy link
Author

cakesoft-shashank commented Dec 30, 2024

I followed local installation, and the library works perfectly. I'm currently using it in a nodejs server project. After cloning the repo, I simply ran yarn build to build it.

@zoedberg
Copy link
Contributor

After building it locally what files do you find in rgb-lib/bindings/c-ffi/target/debug/?

@cakesoft-shashank
Copy link
Author

Screenshot 2024-12-30 at 6 03 46 PM

@zoedberg
Copy link
Contributor

zoedberg commented Dec 30, 2024

And what files do you find in node_modules/rgb-lib/rgb-lib/bindings/c-ffi/target/debug/ (when installing from the npm registry)?

@cakesoft-shashank
Copy link
Author

The folder is empty
Screenshot 2024-12-30 at 6 26 22 PM

@zoedberg
Copy link
Contributor

zoedberg commented Dec 30, 2024

I think you are looking into the wrong node_modules directory. I was referring to the path mentioned in the error logs:

npm error ld: unknown file type in '/project/node_modules/rgb-lib/rgb-lib/bindings/c-ffi/target/debug/librgblibcffi.so'

From the screenshot it's not clear if you are showing the correct path and if the directory is actually empty.

@zoedberg
Copy link
Contributor

@cakesoft-shashank I think I understood the cause of the error. Please try to run npm run build && npm pack, move the generated archive (rgb-lib-0.3.0-alpha.10.tgz) to an empty directory and run npm init and then npm install rgb-lib-0.3.0-alpha.10.tgz, this last command should give you the same errors you see when installing from the npm registry. If you confirm this then I'll push a fix and ask you to repeat the same on that branch

@cakesoft-shashank
Copy link
Author

Getting this error when installing tar in an empty dir

npm ERR! ld: warning: search path '~/Workspace/rgb-lib-nodejs/tmp/node_modules/rgb-lib/rgb-lib/bindings/c-ffi/target/debug/' not found
npm ERR! ld: library 'rgblibcffi' not found

@zoedberg
Copy link
Contributor

Ok. Now please redo the same but on the include_dylib branch

@cakesoft-shashank
Copy link
Author

npm install rgb-lib-0.3.0-alpha.10.tgz executed successfully

@zoedberg
Copy link
Contributor

Ok, good. We'll need to decide if we should include the dylib in the package or use other solutions to avoid making the package too big. Currently the team is on holiday though, so I'm not sure when we'll be able to do this

@cakesoft-shashank
Copy link
Author

Ok, please let me know when you update. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants