13

When attempting to import Connection from @solana/web3.js, this appears when it is run:

bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)

It appears to still run, but I am concerned about what it may impact. Has anyone come across a solution to this?

4
  • Were you able to find the solution ?
    – WowBow
    Commented Nov 4, 2022 at 18:32
  • Not yet. I am still experiencing this issue. I'm not worried about it until I get to production with my project. Maybe soon the library will be updated to fix it for everyone.
    – OCDev
    Commented Nov 10, 2022 at 2:12
  • I've tried all the above solution but it didn't worked for me. Will update when I'll succeed in solving this.
    – G.Courmont
    Commented Jun 19, 2023 at 6:25
  • Tried the below answers, still can not get it work in Mac. ( I have latest python, xcode dev tools, node-gyp)
    – Yarco
    Commented Mar 19 at 2:08

7 Answers 7

15

None of the answers above go to the root cause of the issue and won't solve it, depending on how you are building the environment and running the application.

In my case, the error was occurring in an acceptance tests setup using a very simple docker image starting from node:21.4.0-bookworm-slim. Notice the *-slim part, which means an image with the absolute minimal preinstalled packages.

FROM node:21.4.0-bookworm-slim

WORKDIR /code
COPY package* tsconfig.json /code
RUN npm install

Of course, running the tests, which happens to use bigint-buffer, was displaying the warning. Although nothing was failing, it was a performance concern (maybe...). In any case, I can't sleep with these warnings polluting my terminal.

$ docker compose exec client npm run test:acceptance

> [email protected] test:acceptance
> rm -rf ./dist/* && tsc && node --test dist/*.test.js

bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)
✔ reads own balance (53.348432ms)
▶ creates/deletes PDA
  ✔ fails for non-admin user (12.346694ms)
  ✔ fails for insuficient lamports (7.776273ms)
  ...

Running npm run rebuild as suggested inside the container didn't help. Digging deeper, it turns out that bigint-buffer uses native C bindings for performance reasons, but as such it requires certain dependencies to exist on the host to compile the file written in C. In case these dependencies are not there, it will fallback gracefully to JS implementation, which will still work, but will be less performant.

The build is performed by a tool called node-gyp. This is not very clear from the bigint-buffer perspective, but in node-gyp the dependencies are clearly described in their README:

  • A supported version of Python
  • make
  • A proper C/C++ compiler toolchain, like GCC

In my Debian setup, all I needed was to install python3 and build-essential (which contains make and gcc), adding the following to the Dockerfile before running npm install (so the OS dependencies are there when bigint-buffer is installed by npm):

RUN apt update \
    && apt install --assume-yes --no-install-recommends \
        build-essential \
        python3

If you are running this locally, of course you can just install the equivalent dependencies directly on your computer. Of course if you are using another distro, MacOS or Windows you'll need different dependencies, but the spirit is same.

And done! Optimized native big numbers are now used and no warning is displayed anymore!

2
  • Thanks for this investigation. It works nicely.
    – chalda
    Commented Dec 19, 2023 at 17:51
  • Installing build-essential worked :) Thanks. Commented Feb 2 at 4:29
5

I was having the same issue and npm rebuild solved the issue.

3
  • 1
    This solution did not work for me. Even replacing node_modules entirely did not fix this for me.
    – OCDev
    Commented Nov 10, 2022 at 2:11
  • 1
    ` After some tinkering around with the project I ended up using this command and it worked as well. I believe it has something to do with the react version being used on your local environment. Would you mind trying these commands? npm i -g npm-check-updates ncu -u npm install
    – Plex
    Commented Nov 11, 2022 at 3:07
  • Interesting. I'm into Svelte and never installed React. The system is fresh and I don't think I installed Svelte yet either. After I ran ncu -u and did install again, I continue to experience the problem.
    – OCDev
    Commented Nov 12, 2022 at 3:11
3
npm install bigint-buffer

This utility is necessary because BigInts, as proposed, do not support direct conversion between Buffers (or UInt8Arrays), but rather require conversion from buffers to hexadecimal strings then to BigInts, which is suboptimal.

https://www.npmjs.com/package/bigint-buffer

2

Did you run npm rebuild? That seemed to fix it for me and a few other people on discord...

1
  • 1
    This solution did not work for me. Even replacing node_modules entirely did not fix this for me.
    – OCDev
    Commented Nov 10, 2022 at 2:12
1

Ubuntu 22.04.2 LTS fixed with

sudo apt -install build-essential
1
  • Amazing! Thanks this fixed the issue on the server. Commented Aug 28 at 15:31
0
  1. npm install bigint-buffer
  2. npm rebuild
  3. npm start

--> It work for me

1
  • 1
    This seems like a duplicate of the @609Consulting answer.
    – mikemaccana
    Commented Jan 5 at 17:29
0

The solution is to use nvm to install the lts version of node and npm.

You can find the node version manager here: https://github.com/nvm-sh/nvm

nvm install --lts
nvm use --lts

the latest version of node and npm also removed the bigint warning, but it introduced a new one related to punycode. (A deprecation warning)

using the lts version will resolve that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.