Babel 5.8.38忽略Node.js中的等待

Babel 5.8.38忽略Node.js中的等待,node.js,async-await,babeljs,Node.js,Async Await,Babeljs,我对Babel 5.8.38有问题,正在Node.js中等待 我的代码是这样的: /** * Imports */ import {signature} from '../core/antpool'; import log from '../core/logging'; import config from '../config'; import {sendLog as sendEmailLog, EmailTemplate} from '../core/email'; import {re

我对Babel 5.8.38有问题,正在Node.js中等待 我的代码是这样的:

/**
 * Imports
 */
import {signature} from '../core/antpool';
import log from '../core/logging';
import config from '../config';
import {sendLog as sendEmailLog, EmailTemplate} from '../core/email';
import {rethinkdb, Decorators as DBDecorators} from '../core/db';
import request from 'request';

const tables = {
    AntpoolAccount: 'CronAntpoolAccount'
};

class Antpool {

    @DBDecorators.table(tables.AntpoolAccount)
    static async account(coin) {
        var nonce = Date.now();
        request.post({
            url: config.antpool.baseUrl + '/api/account.htm',
            json: true,
            form: {
                key: config.antpool.key,
                nonce: nonce,
                signature: signature(nonce),
                coin: coin
            }
        }, function (err, httpResponse, body) {
            if (err || httpResponse.statusCode != 201) {
                log.error(err, '[CRON][Antpool][Account] Connection problem');
                sendEmailLog(EmailTemplate.LOG, {
                    message: '[CRON][Antpool][Account] Connection problem'
                });
                return false;
            }

            var out = JSON.parse(body);
            if (out.code != 0) {
                log.error(err, '[CRON][Antpool][Account] Error response('+out.code+'): '+out.message);
                sendEmailLog(EmailTemplate.LOG, {
                    message: '[CRON][Antpool][Account] Error response('+out.code+'): '+out.message
                });
                return false;
            }

            // Add to database
            let obj = {
                earn24: out.data.earn24Hours,
                earnTot: out.data.earnTotal,
                paidOut: out.data.paidOut,
                balance: out.data.balance,
                createdAt: new Date()
            };

            // Insert into database
            let insert = await this.table.insert(obj).run();

            if(insert) {
                return true;
            } else {
                return false;
            }

        });
    }

}

/**
 * Exports
 */
export {Antpool};
我得到的是唯一一个与等待有问题的错误

SyntaxError: .../antpool.js: Unexpected token (59:22)

            // Insert into database
            let insert = await this.table.insert(obj).run();
我在想什么是可以接受等待的解决方案。这是否有点奇怪,因为在代码的其他部分,wait工作得很好。 不确定问题到底是什么,但花了大约两天的时间找到了问题所在

我通过以下方式调用脚本:

/**
 * Automatically hook babel into all node requires.
 */
require('babel/register')({
    optional: ['es7.asyncFunctions', 'es7.classProperties', 'es7.decorators']
});

/**
 * Start application worker.
 */
require('./src/worker');

非常感谢您的帮助。

关键字
wait
只能用于标记为
async
的函数中。您试图使用的函数
等待

,函数(err,httpResponse,body){
…

未标记为
async
,因此无法编译


更多信息:

关键字
await
只能在标记为
async
的函数中使用。您尝试在其中使用
await
的函数:

,函数(err,httpResponse,body){
…

未标记为
async
,因此无法编译


更多信息:

您在未作为异步签名的函数“function(err,httpResponse,body)”中使用wait您在未作为异步签名的函数“function(err,httpResponse,body)”中使用wait下一个问题是:执行:_cronsAntpool2['default'].帐户('btc'))无法读取未定义的属性“account”。此问题似乎存在于hapi cron作业及其与的组合:execute:Antpool.account('btc')中这似乎与您发布的代码无关。但是,某些函数的异步回调似乎存在一些问题。当您意识到调用了哪个函数时,您可能会意识到它是
,此
设置为
未定义的
。然后您需要找到传递回调的位置并将其绑定到某个c带有
.bind(concreteObject)
的oncrete对象
.bind()
的详细信息:下一个问题出现了:执行:_cronsAntpool2['default'].account('btc')无法读取未定义的属性'account'。这似乎是hapi cron作业的某个地方的问题,并与以下组合:execute:Antpool.account('btc'))这似乎与您发布的代码无关。但是,某些函数的异步回调似乎存在一些问题。当您意识到调用了哪个函数时,您可能会意识到它是
,此
设置为
未定义的
。然后您需要找到传递回调的位置并将其绑定到某个c使用
.bind(concreteObject)
使用
.bind()
创建混凝土对象的详细信息: