无法要求node-wit

我一直在使用node-wit v3.3.2今天,我想更新并使用最新版本。

但是我无法导入节点机智。 不知道为什么。 我只是复制了他们的文档中给出的代码。

'use strict' var MY_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" const {Wit, log} = require('node-wit'); const client = new Wit({ accessToken: MY_TOKEN, actions: { send(request, response) { return new Promise(function(resolve, reject) { console.log(JSON.stringify(response)); return resolve(); }); }, myAction({sessionId, context, text, entities}) { console.log(Session ${sessionId} received ${text}); console.log(The current context is ${JSON.stringify(context)}); console.log(Wit extracted ${JSON.stringify(entities)}); return Promise.resolve(context); } }, logger: new log.Logger(log.DEBUG) // optional }); 

terminal显示这个:

 const {Wit, log} = require('node-wit'); ^ SyntaxError: Unexpected token { at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10) at startup (node.js:139:18) at node.js:974:3 

可能是您正在使用的节点版本。 使用较低版本时,您需要使用--harmony_destructuring标志。

取自: https : //github.com/wit-ai/node-wit

 # Node.js <= 6.xx, add the flag --harmony_destructuring node --harmony_destructuring examples/basic.js <MY_TOKEN> # Node.js >= v6.xx node examples/basic.js <MY_TOKEN>