我的JavaScript文件赢了,因为BigInt错误会运行

发布于 2025-01-28 18:43:02 字数 731 浏览 3 评论 0原文

我正在尝试使用 @metaplex/js进行一些NFT造币。通常,我的.js文件正常工作,但是当我运行文件时,此错误会出现。

bigint:无法加载绑定,将使用纯JS(尝试NPM运行重建?)

我真的没有得到什么含义。因此,我尝试运行NPM Run Rebuild,但据说重建是一个缺少的脚本,我找不到安装它的方法。

这是我的代码:

import { Connection, programs} from "@metaplex/js";
import { Loader } from "@solana/web3.js";
const { metadata: {Metadata}} = programs;


const connection = new Connection("devnet");
const tokenPublicKey = 'my_adress';

const run = async() => {
    try{
        const ownedMetadata = await Metadata.Loader(connection,tokenPublicKey)
        console.log(ownedMetadata)
    }
    catch{
        console.log('Failed to fetch')
    }

};

run();

如果您有任何想法,或者仅仅解释了我的错误含义,我将不胜感激。

I am trying to use @metaplex/js to do some NFT minting. Usually my .js files work properly but when I run the file this error comes up.

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

I don't really get what that means. So, I tried to run npm run rebuild but rebuild is said to be a missing script and I couldn't find a way to install it.

Here is my code:

import { Connection, programs} from "@metaplex/js";
import { Loader } from "@solana/web3.js";
const { metadata: {Metadata}} = programs;


const connection = new Connection("devnet");
const tokenPublicKey = 'my_adress';

const run = async() => {
    try{
        const ownedMetadata = await Metadata.Loader(connection,tokenPublicKey)
        console.log(ownedMetadata)
    }
    catch{
        console.log('Failed to fetch')
    }

};

run();

If you have any idea, or simply an explanation of what my error means, I'd be grateful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情仇皆在手 2025-02-04 18:43:02

您会遇到此错误,因为嵌套的依赖性具有在平台中无法成功的汇编步骤。 此问题提供了一个很好的解释。

[...]发生这种情况是因为我们的一个依赖关系(BigInt-Buffer)在安装上运行一个汇编步骤,并且这可能出于几个原因而失败。原因之一是您的系统可能没有库正在寻找的构建工具。您可以在Windows上安装这些构建工具(请参阅 https://wwww.npmjs.com/包装/Windows-Build-tools ),但是您实际上并不需要,因为它会自动落入纯JS解决方案。虽然我同意...警告很烦人。

但是,这应该给您警告,并且仍然允许您编译代码。

值得注意的是,Metaplex的当前JS SDK将被弃用新的: https://github.com/metaplex-foundation/js-next

使用新的JS SDK,您可以使用以下代码获取NFT。

import { Metaplex } from "@metaplex-foundation/js";
import { Connection, clusterApiUrl } from "@solana/web3.js";

const connection = new Connection(clusterApiUrl("mainnet-beta"));
const metaplex = new Metaplex(connection);
const mintAddress = new PublicKey("ATe3DymKZadrUoqAMn7HSpraxE4gB88uo1L9zLGmzJeL");

const nft = await metaplex.nfts().findByMint({ mintAddress });

You are getting this error because a nested dependency has a compilation step that might not succeed in your platform. This issue provides a good explanation.

[...] This happens because one of our dependencies (bigint-buffer) runs a compilation step on installation and this can step may fail for a couple of reasons. One of the reasons is that your system might not have the build-tools the library is looking for. You can install these build tools on Windows (see https://www.npmjs.com/package/windows-build-tools), but you don't actually need to as it automatically falls back to a pure JS solution instead. Though I agree... that warning is very annoying.

However, this should give you a warning and still allow you to compile your code.

It is worth noting that the current JS SDK from Metaplex is going to be deprecated in favour of the new one: https://github.com/metaplex-foundation/js-next

With the new JS SDK, you can fetch an NFT using the following piece of code.

import { Metaplex } from "@metaplex-foundation/js";
import { Connection, clusterApiUrl } from "@solana/web3.js";

const connection = new Connection(clusterApiUrl("mainnet-beta"));
const metaplex = new Metaplex(connection);
const mintAddress = new PublicKey("ATe3DymKZadrUoqAMn7HSpraxE4gB88uo1L9zLGmzJeL");

const nft = await metaplex.nfts().findByMint({ mintAddress });
玉环 2025-02-04 18:43:02

我也经历了这个问题。就我而言,它是在接受测试的设置中使用非常简单的docker映像开始的,从节点开始:21.4.0-book worm-slim。请注意* - Slim零件,这是指具有绝对最小预装软件包的图像。

FROM node:21.4.0-bookworm-slim

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

当然,运行碰巧使用bigint-buffer的测试正在显示警告。尽管没有任何事情失败,但这是一个表演问题(也许...)。无论如何,我无法入睡这些警告污染我的航站楼。

$ 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)
  ...

运行NPM运行重建在容器中建议的无济于事。更深入地挖掘,事实证明,出于绩效原因,bigint-buffer使用本机C绑定,但是因此,如果这些依赖关系为不存在,它将优雅地退回JS实施,这仍然可以起作用,但性能较低。

该构建由称为node-gyp的工具执行。从bigint-buffer角度来看,这不是很清楚,但是在node-gyp中,依赖项在其 readme

  • python的支持版本
  • 代码>
  • 适当的C/C ++编译器工具链,例如GCC

在我的Debian设置中,我所需要的只是安装python3build> build-Essential((其中包含makegcc),将以下内容添加到dockerfile 之前运行运行npm npm install (因此,当bigint-buffer> npm安装时,OS依赖项就在那里:

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

如果您在本地运行此此操作,那么您当然可以直接安装等效的依赖项在您的计算机上。当然,如果您使用另一个发行版,macos或窗口,则需要不同的依赖性,但是精神是相同的。

并完成了!现在使用了优化的本地大数字,并且不再显示警告!

I experienced this issue as well. In my case, it 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!

微暖i 2025-02-04 18:43:02

为了处理警告“未能加载绑定,将使用纯JS(尝试NPM运行重建?)”在Bigint-Buffer模块中,如果它不影响您的功能,则可以将其注释。由于此警告表明未加载本机绑定,并且将使用纯JS后备,因此通常在大多数情况下都不关键。

// console.warn('bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
Search "Failed to load bindings, pure JS will be used (try npm run rebuild?)" (2 hits in 2 files of 1973 searched) [Normal]
  `C:\Users\******\Desktop\sol\node_modules\bigint-buffer\dist\node.js` (1 hit)
    Line 10:         console.warn('bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
  `C:\Users\*****\Desktop\sol\node_modules\bigint-buffer\src\index.ts` (1 hit)
    Line 16:         'bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
Search "bigint:" (37 hits in 23 files of 1973 searched) [Normal]

To handle the warning "Failed to load bindings, pure JS will be used (try npm run rebuild?)" in the bigint-buffer module, you can comment it out if it doesn't affect your functionality. Since this warning suggests that a native binding isn't loaded and the pure JS fallback will be used, it typically isn't critical for most cases.

// console.warn('bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
Search "Failed to load bindings, pure JS will be used (try npm run rebuild?)" (2 hits in 2 files of 1973 searched) [Normal]
  `C:\Users\******\Desktop\sol\node_modules\bigint-buffer\dist\node.js` (1 hit)
    Line 10:         console.warn('bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
  `C:\Users\*****\Desktop\sol\node_modules\bigint-buffer\src\index.ts` (1 hit)
    Line 16:         'bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
Search "bigint:" (37 hits in 23 files of 1973 searched) [Normal]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文