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

web3.min.js v1.2.2: Uncaught ReferenceError: regeneratorRuntime is not defined #3155

Closed
gpersoon opened this issue Oct 24, 2019 · 4 comments · Fixed by #3202
Closed

web3.min.js v1.2.2: Uncaught ReferenceError: regeneratorRuntime is not defined #3155

gpersoon opened this issue Oct 24, 2019 · 4 comments · Fixed by #3202
Labels
1.x 1.0 related issues Bug Addressing a bug

Comments

@gpersoon
Copy link

Description

Error "Uncaught ReferenceError: regeneratorRuntime is not defined" occurred when calling a smart contract function. The error shows in the developer console.

Expected behavior

No error
Note: with a browserified version of web3.js 1.2.1 this error doesn't occur

Actual behavior

An error is shown in the developer console

Workaround

A workaround is to include polyfill.min.js:

<script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script> 

Steps to reproduce the behavior

npm install web3

Use chrome and metamask on rinkeby network to load following html page:

<html>
    <head>
        <script src=".........../node_modules/web3/dist/web3.min.js"></script>               
    </head>
<body>
<script>   
    async function asyncloaded() { 
        await ethereum.enable();
        web3 = new Web3(Web3.givenProvider);
        var ERC777ABI = [{"constant": false,"inputs": [{"internalType": "address","name": "recipient","type": "address"},{"internalType": "uint256","name": "amount","type": "uint256"},{"internalType": "bytes","name": "data","type": "bytes"}],        "name": "send","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"}];
        const ERC777 = new web3.eth.Contract(ERC777ABI, "0x51a8e7fEC5639Eb6861a674E4F46148561d5c5c6");  // rinkeby
        accounts=await web3.eth.getAccounts();        
        var result = await ERC777.methods.send(accounts[0],1,"0x77").send({from: accounts[0]});
    }
    window.addEventListener('load', asyncloaded);  
    </script>     
</body>
</html>

The deployed smart contact is an ERC777 contract.

Error Logs

8inpage.js:1 Uncaught ReferenceError: regeneratorRuntime is not defined
at web3.min.js:1
at n (web3.min.js:1)
at web3.min.js:1
at Array.forEach ()
at Object.callback (web3.min.js:1)
at MetamaskInpageProvider. (web3.min.js:1)
at u (inpage.js:1)
at MetamaskInpageProvider.a.emit (inpage.js:1)
at a. (inpage.js:1)
at u (inpage.js:1)

Gists

Versions

  • web3.js: 1.2.2
  • nodejs:
  • browser: Chrome
  • ethereum node:
  • metamask 7.3.1
@nivida
Copy link
Contributor

nivida commented Oct 24, 2019

Thanks for opening this issue! We have fixed this in PR #3062.

I couldn't reproduce this issue with the following steps:

  1. npm install web3

  2. Creating of HTML:

<!DOCTYPE html>
<html>
<head>
    <title>
        dapp example
    </title>
    <script src="./node_modules/web3/dist/web3.min.js">
    </script>
    <script>
      var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/'));
      web3.eth.getTransaction('0xd540f813d46953f5bf7c0b3797572ff6b73eee0eeadfac071baee0da9a7a9b5a').then(console.log);
    </script>
</head>
<body></body>
</html>
  1. Testing this HTML file in Brave.

Response:

{blockHash: "0xd49d1dae2774704b27aaf41f0fd16ed84486511801c3bd82bf2065e561d4e677", blockNumber: 4817038, from: "0xa4A8C40CF200e548305001B9Af9965722c70C6AD", gas: 250000, gasPrice: "1000000000", …}blockHash: "0xd49d1dae2774704b27aaf41f0fd16ed84486511801c3bd82bf2065e561d4e677"blockNumber: 4817038from: "0xa4A8C40CF200e548305001B9Af9965722c70C6AD"gas: 250000gasPrice: "1000000000"hash: "0xd540f813d46953f5bf7c0b3797572ff6b73eee0eeadfac071baee0da9a7a9b5a"input: "0xe9c6c176000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000bf065813af0ab2ade7b29be3bdd8939ca79aad5f14a73e9f3c0aeb7e9c45d88476db1e"nonce: 180222r: "0xaf46e46b5a3248cd5eae579a72191210e0b721909b94d0e1d82e4ee3c55b4768"s: "0x44e81ed505f7024320eade3f3255b65ca773008d70af19fcfe4844cf0f0d1cb9"to: "0xA4f7E95205ac2e79b85528a0B63587bD1d5Eff78"transactionIndex: 26v: "0x1c"value: "0"__proto__: Object

@nivida nivida added 1.x 1.0 related issues more information needed labels Oct 24, 2019
@gpersoon
Copy link
Author

@nivida I'dont understand your questions:

  • It's not really fixed because I can reproduce the issue.
  • I also tried it on Brave and have the same issue.
  • I don't see the relation with the "web3.eth.getTransaction" example.
  • The html file has to be run from a webserver for metamask to work.
  • I assume you can't reproduce the issue? Do you see any other messages?
  • If you see "Alert: Transaction error: Exception thrown in contract code", you can ignore that and still try to do the transaction; i still get the error afterwards; actually before transaction is completed.
  • I'm using windows 10

@nivida
Copy link
Contributor

nivida commented Oct 24, 2019

Now I was able to reproduce your issue. It's only on sending of a transaction and is a bug in our build pipeline. It doesn't add the required regeneratorRuntime function to the bundle. The useBuiltIns options property is missing in our build pipeline.

This:

[
  '@babel/preset-env',
  {
    useBuiltIns: 'usage'
  }
]

is missing here.

Sorry for the confusion! I thought it's more a general issue with the async/await handling of web3.js.

@nivida nivida added Bug Addressing a bug CI and removed more information needed labels Oct 24, 2019
@pepihasenfuss
Copy link

@gpersoon Thank you for your workaround. Including the polyfill.min.js did work for me.... after a lot of pain with 1.22 and some versions before. Looking forward to a new release of web3.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants