Unexpected token (6:6)

2019-08-17 17:18发布

问题:

I am trying to generate a business network archive but I am getting the following error while running composer archive create -t dir -n .

Creating Business Network Archive
Looking for package.json of Business Network Definition

SyntaxError: Failed to parse /Users/xxxx@xxxx.com/fabric-tools/tutorial-network/lib/logic.js: Unexpected token (6:6)

Command failed

Unexpected token (6:6)? the content of the logic.js are below:

cat lib/logic.js
/**
* Track the trade of a commodity from one trader to another
* @param {org.acme.mynetwork.Trade} trade - the trade to be processed
* @transaction
*/
async function tradeCommodity(trade) {
    trade.commodity.owner = trade.newOwner;
    let assetRegistry = await getAssetRegistry('org.acme.mynetwork.Commodity');
    await assetRegistry.update(trade.commodity);
}

回答1:

In composer v0.16.x, async and ES6 keywords are not supported. There is an issue with it. You can check here. If you want to use these keywords you need to upgrade composer to v0.17.4 or higher.



回答2:

I was able to get answer for this on the Hyperledger community support and it is also exactly what @mohammadjh mentioned here. The version of composer that I initially had was outdated and getting the latest one resolved the issue. Here is how you get the latest version: npm install -g composer-cli