【问题标题】:Unable to require node-wit无法要求节点机智
【发布时间】:2016-08-31 08:05:41
【问题描述】:

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

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

'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
});

终端显示如下:

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

【问题讨论】:

    标签: node.js wit.ai


    【解决方案1】:

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

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

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

    【讨论】:

    • 好吧,就是这样!非常感谢!不敢相信我错过了这个。
    猜你喜欢
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多