【问题标题】:NEAR protocol ReferenceError: Buffer is not definedNEAR 协议 ReferenceError: 缓冲区未定义
【发布时间】:2022-01-14 16:44:29
【问题描述】:

我在尝试使用 near-api-js 时收到 ReferenceError: Buffer is not defined

相关的代码行是:

export const near = new Near({
  networkId,
  keyStore: new keyStores.BrowserLocalStorageKeyStore(),
  nodeUrl,
  walletUrl,
  headers: null,
});

export const walletConnection = new WalletConnection(near, appKeyPrefix);

walletConnection.requestSignIn({ // This line causes the problem
    contractId,
    methodNames: [],
});

我的项目是全新安装的 Gatsby。

任何想法我缺少什么?

【问题讨论】:

    标签: nearprotocol


    【解决方案1】:

    我跑了yarn add buffer

    然后我在我的文件前面加上这些行:

    import * as buffer from 'buffer';
    (window as any).Buffer = buffer.Buffer; // https://github.com/isaacs/core-util-is/issues/27#issuecomment-878969583
    

    https://github.com/isaacs/core-util-is/issues/27#issuecomment-878969583

    然后它似乎工作了。

    但这感觉就像一个奇怪的黑客,我没想到需要做这样的事情。但是我在任何 NEAR 文档中都找不到更好的方法。我很好奇其他人会在这里提出什么建议。

    【讨论】:

      猜你喜欢
      • 2021-11-02
      • 1970-01-01
      • 2010-09-25
      • 2022-01-21
      • 2022-01-28
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多