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

bun:test ReferenceError #576

Open
jonator opened this issue Nov 19, 2024 · 5 comments
Open

bun:test ReferenceError #576

jonator opened this issue Nov 19, 2024 · 5 comments

Comments

@jonator
Copy link

jonator commented Nov 19, 2024

Getting this when running tests

# Unhandled error between tests
-------------------------------
22 |         return this;
23 |     }.call(null) ||
24 |     Function('return this')();
25 | 
26 | var core_contract_common_pb = require('../../core/contract/common_pb.cjs');
27 | goog.object.extend(proto, core_contract_common_pb)
@Satan-web3
Copy link
Contributor

Did you add cjs config like here?

@lljxx1
Copy link

lljxx1 commented Nov 26, 2024

I meet the same issue too @Satan-web3

22 |         return this;
23 |     }.call(null) ||
24 |     Function('return this')();
25 | 
26 | var core_contract_common_pb = require('../../core/contract/common_pb.cjs');
27 | goog.object.extend(proto, core_contract_common_pb);
                        ^
ReferenceError: Can't find variable: proto
      at /home/runner/work/project/node_modules/tronweb/lib/esm/protocol/core/contract/balance_contract_pb.cjs:27:20

Bun v1.1.26 (Linux x64 baseline)

@Satan-web3
Copy link
Contributor

Can you give a example reproducing this error?

@lljxx1
Copy link

lljxx1 commented Nov 26, 2024

Can you give a example reproducing this error?

Hi, my errors appeared in GitHub actions with a 10% chance.

test.ts

import * as tronweb from "tronweb";
import axios from "axios";

async function setup() {
  const { data: availableAccounts } = await axios.get(
    "http://127.0.0.1:9098/admin/accounts-json",
  );
  const { privateKeys } = availableAccounts;
  const [firstPrivateKey] = privateKeys;
  const tronWeb = new tronweb.TronWeb({
    fullHost: chain.httpRpcUrl,
    privateKey: firstPrivateKey,
  });

  const address = tronWeb.address.fromPrivateKey(firstPrivateKey);

  {
    const freezeTx = await tronWeb.transactionBuilder.freezeBalanceV2(
      1 * 1e6,
      "ENERGY",
    );
    const signedTransaction = await tronWeb.trx.sign(freezeTx, firstPrivateKey);
    await tronWeb.trx.sendRawTransaction(signedTransaction);
  }

  await new Promise((resolve) => setTimeout(resolve, 1 * 1000));

  const transaction = await tronWeb.transactionBuilder.createSmartContract(
    {
      abi: trc20COntract.abi,
      bytecode: trc20COntract.byteCode,
      feeLimit: 1000000000,
      callValue: 0,
      parameters: [],
    },
    address,
  );
  const signedTransaction = await tronWeb.trx.sign(
    transaction,
    firstPrivateKey,
  );
  await tronWeb.trx.sendRawTransaction(signedTransaction);
}

@Satan-web3
Copy link
Contributor

As I've tested, bun didn't load cjs file in the correct order when using esm as entry. So I recommend you to use commonjs style or drop the use of bun.

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

3 participants