运行我的.js文件时异步awaitCurrentBlock()中的意外标识符

时间:2018-08-26 14:00:21

标签: javascript node.js async-await syntax-error

使用节点compile.js运行compile.js文件时遇到问题。 我的代码:

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();

运行后:节点compile.js

错误日志:

/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)

我做了分析,似乎“ const HDWalletProvider = require('truffle-hdwallet-provider');”在/home/edureka/sankalp_practice/inbox/node_modules/eth-block-tracker/src/index.js中调用函数async awaitCurrentBlock()。

所以请让我知道如何解决它。

系统:Ubuntu 节点版本:v6.11.4 npm版本:5.4.2

1 个答案:

答案 0 :(得分:0)

您的依赖项使用看起来像节点8. *的“ async awaitCurrentBlock”,在这种情况下,您只是使用过旧的节点版本。您需要该依赖项,然后必须更新,但这将以另一种方式破坏您的代码->您要导入依赖项“ async”和“ await”,它们是节点8中的保留关键字,因此您必须更新语法也是如此