Search code examples
hyperledger-composer

Hyperledger composer fails to create .bna file. Unexpected token.


I'm trying to generate a .bna file following this -> https://hyperledger.github.io/composer/latest/tutorials/developer-tutorial.html tutorial. But when I'm running the command 'composer archive create -t dir -n .' Instead of generating a new .bna file I get the following error: code in logic.js :

/**
 * Track the trade of a commodity from one trader to another
 * @param {org.example.biznet.Trade} trade - the trade to be processed
 * @transaction
 */
async function tradeCommodity(trade) {
    trade.commodity.owner = trade.newOwner;
    let assetRegistry = await getAssetRegistry('org.example.biznet.Commodity');
    await assetRegistry.update(trade.commodity);
}
console.log("Node?");


SyntaxError: Failed to parse /Users/marcello/tutorial-network/lib/logic.js: Unexpected token (6:6)

It looks like composer doesn't recognise the async syntax. When I run this code using node everything is ok.

It's my full repo of the project: https://github.com/Jonbi2/marcellos-hyperledger-composer-repo I use this dependencies: node : v8.11.3 npm : 5.6.0 composer : v0.16.6 Docker version 18.03.1-ce, build 9ee9f40 Thanks for help


Solution

  • The problem is that you have Composer v0.16 installed, but you are following a tutorial for v0.19.x. There are many important changes between those versions, including support for async functions in v0.19.x

    This Q/A earlier today has a very similar problem with steps to fix.