首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我在这个Node JS代码中得到语法错误?

为什么我在这个Node JS代码中得到语法错误?
EN

Stack Overflow用户
提问于 2021-05-22 20:29:39
回答 1查看 108关注 0票数 2

您好,我从Node开始,并尝试按照文档over here编写代码。我按此做了所有的事情,但我的误差越来越小了。

代码语言:javascript
复制
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代码

代码语言:javascript
复制
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

代码语言:javascript
复制
  {

  "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-worker”也在同一目录中。我不知道我哪里做错了,任何帮助都是非常感谢的!

EN

回答 1

Stack Overflow用户

发布于 2021-05-22 20:35:07

看看这两行,您正在导入和使用同名的常量变量。

代码语言:javascript
复制
import Bumblebee from "bumblebee-hotword";

const Bumblebee = require('bumblebee-hotword');

更改常量变量的名称可以解决您的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67649475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档