![](/img/trans.png)
[英]I am new to node.js.while writing a code iam getting an syntax error unexpected identifier at config=
[英]Why I am getting Syntax error in this Node JS code?
嗨,我从 Node Js 开始,并按照此处的文档尝试了代码。 我做了相应的一切,但我得到了错误。
const Bumblebee = require('bumblebee-hotword');
^
SyntaxError: Identifier 'Bumblebee' has already been declared
at Loader.moduleStrategy (node:internal/modules/esm/translators:147:18)
at async link (node:internal/modules/esm/module_job:48:21)
这是 index.js 代码
import Bumblebee from "bumblebee-hotword";
const Bumblebee = require('bumblebee-hotword');
let bumblebee = new Bumblebee();
// set path to worker files
bumblebee.setWorkersPath('/bumblebee-workers');
// add hotword
bumblebee.addHotword('jarvis');
// set sensitivity from 0.0 to 1.0
bumblebee.setSensitivity(1.0);
bumblebee.on('hotword', function(hotword) {
// YOUR CODE HERE
console.log('hotword detected:', hotword);
});
bumblebee.start();
这是 package.json
{
"name": "Hotword_template",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"bumblebee-hotword": "^0.2.1"
}
}
所需的目录“bumblebee-workers”也在同一目录中。 我不知道我在哪里做错了,非常感谢任何帮助!
看看这两行,您正在导入和使用同名的常量变量。
import Bumblebee from "bumblebee-hotword";
const Bumblebee = require('bumblebee-hotword');
更改const变量的名称可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.