1

I am facing an issue while running my compile.js file using node compile.js . My code:

const async = require('asyncawait/async');
const await = require('asyncawait/await');

const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');

const provider = new HDWalletProvider(
    'nut plug quality level uncle jeans retire guide eagle gossip cluster sudden',
    'https://rinkeby.infura.io/v3/37097b2064214600912ad8a746ff433a'
);

const web3 = new Webs(provider);

const deploy = async (() => {
    const accounts = await (web3.eth.Accounts());
    console.log('Attempting to deploy from account', accounts[0]);

    const result = await(new web3.eth.Contract(JSON.parse(interface))
    .deploy({ data: bytecode, arguments: ['Hi there!'] })
    .send({gas: '1000000', from: accounts[0]})
    );

    console.log('contract deployed to', result.options.address);
});

deploy();

After running : node compile.js

Error log:

/home/edureka/sankalp_practice/inbox/node_modules/eth-block-tracker/src/index.js:38

async awaitCurrentBlock () {
        ^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected token function
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/edureka/sankalp_practice/inbox/node_modules/web3-provider-engine/index.js:4:25)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)

I did my analysis and it seems that "const HDWalletProvider = require('truffle-hdwallet-provider');" is calling for function async awaitCurrentBlock () in /home/edureka/sankalp_practice/inbox/node_modules/eth-block-tracker/src/index.js.

So please let me know how to resolve it.

system: Ubuntu version of node: v6.11.4 version of npm : 5.4.2

  • Possible duplicate of [SyntaxError: Unexpected token function - Async Await Nodejs](https://stackoverflow.com/questions/37815790/syntaxerror-unexpected-token-function-async-await-nodejs) – t.niese Aug 26 '18 at 14:04
  • 1
    Your node version is to old to support native `async`/`await` – t.niese Aug 26 '18 at 14:05

1 Answers1

0

your dependency uses "async awaitCurrentBlock" that looks like node 8.* in which case you're simply using too old version of node. You want that dependency, then you have to update, but that will break your code in another way -> you're importing dependencies "async" and "await" which are reserved keywords in Node 8, so you'll have to update your syntax too

Kamil Janowski
  • 1,872
  • 2
  • 21
  • 43
  • Yes, it is older version. Actually I had to import async and await as I had to use these functions for my purpose. Is there any other way so that I can use "async awaitCurrentBlock" which is in another file in node_module. I tried with modifying the index.js but its throwing a different error. – sankalp nayak Aug 26 '18 at 14:25