简体   繁体   English

为什么我在此 Node JS 代码中收到语法错误?

[英]Why I am getting Syntax error in this Node JS code?

Hi I am starting with Node Js and tried a code as per the documentation over here .嗨,我从 Node Js 开始,并按照此处的文档尝试了代码。 I did everything accordingly but I am getting below error.我做了相应的一切,但我得到了错误。

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)

Here is the index.js code这是 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();

And here is the package.json这是 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"
}
}

Also the required directory "bumblebee-workers" is in the same directory.所需的目录“bumblebee-workers”也在同一目录中。 I don't know where I am doing wrong, any help is highly appreciated!!我不知道我在哪里做错了,非常感谢任何帮助!

Look at these two lines, you are importing and using constant variable of same name.看看这两行,您正在导入和使用同名的常量变量。

import Bumblebee from "bumblebee-hotword";

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

Changing the name of const variable can solve your problem.更改const变量的名称可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我是 node.js 的新手。在编写代码时,我在 config= 处收到语法错误意外标识符 - I am new to node.js.while writing a code iam getting an syntax error unexpected identifier at config= 在 Windows 的命令行中运行 node server.js 时,为什么会出现语法错误或服务器未定义错误? - Why am I getting a syntax error or server not defined error when running node server.js in command line for windows? 为什么我从node.js收到此错误? - Why am I getting this error from node.js? 为什么我在安装节点 js 时收到此错误 - why i am getting this error while installing node js 为什么在我的节点生产服务器版本上而不是本地版本上出现语法错误? - Why am I getting a syntax error on my node production server build but not my local build? 当我尝试在“node.js”中运行这行代码时,我收到以下错误 - When I try to run this line of code in “node.js”, I am getting the following error 为什么我在 node.js 代码中使用 sql 时出现语法错误 - why i have syntax error when i use sql in my node.js code 我在我的节点 js 代码中收到错误意外的输入结束 - i am getting error unexpected end of input in my node js code 我在 node.js 中收到错误代码“,”预期 ts(1005) - I am getting an error code ',' expected ts(1005) in node.js 为什么我在运行'net'模块node.js时遇到此错误 - Why am i getting this error running 'net' module node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM