Javascript 二进制搜索树(Node.js)-语法错误:意外标识符

Javascript 二进制搜索树(Node.js)-语法错误:意外标识符,javascript,node.js,binary-search-tree,Javascript,Node.js,Binary Search Tree,我已经创建了一个程序(通过node.js运行),该程序应该能够使用各种方法(插入、删除、打印等)创建一个二进制搜索树。它被分成两个独立的文件:Tree.js,它导出函数Tree()(及其方法)和test();和main.js,然后导入函数并运行test() 但是,当我尝试运行main.js时,我收到以下错误消息: SyntaxError: Unexpected identifier at exports.runInThisContext (vm.js:53:16)

我已经创建了一个程序(通过node.js运行),该程序应该能够使用各种方法(插入、删除、打印等)创建一个二进制搜索树。它被分成两个独立的文件:Tree.js,它导出函数Tree()(及其方法)和test();和main.js,然后导入函数并运行test()

但是,当我尝试运行main.js时,我收到以下错误消息:

SyntaxError: Unexpected identifier 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 Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object. (/Users/Anubis/Documents/COMP2406/Assignment 1/main.js:1:77) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) SyntaxError:意外的标识符 在exports.runInThisContext(vm.js:53:16) 在模块处编译(Module.js:373:25) 在Object.Module.\u extensions..js(Module.js:416:10) 在Module.load(Module.js:343:32) 在Function.Module.\u加载(Module.js:300:12) at Module.require(Module.js:353:17) 根据需要(内部/module.js:12:17) 反对。(/Users/Anubis/Documents/COMP2406/Assignment 1/main.js:1:77) 在模块处编译(Module.js:409:26) 在Object.Module.\u extensions..js(Module.js:416:10)
我一直在搜索有问题的语法错误,但到目前为止无法找到它。

代码的第二行有一个基本语法错误:

    module.exports = {
    //Tree object with constructor
    var Tree = function(){
//  ^----- here

您不能在对象初始值设定项中声明变量。

堆栈片段(您使用的
工具栏按钮)用于在浏览器代码中可运行,不用于在浏览器中不可运行的代码,也不用于异常列表。这就完成了任务。谢谢你! SyntaxError: Unexpected identifier 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 Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object. (/Users/Anubis/Documents/COMP2406/Assignment 1/main.js:1:77) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10)
    module.exports = {
    //Tree object with constructor
    var Tree = function(){
//  ^----- here