我正在运行Node.js,并尝试使用以下命令在repl中加载脚本: .load transformscript.js
transformscript.js的前两行如下:
.load rdfMapping.js
.load rdfVocab.js
问题是我收到错误信息'SyntaxError:Unexpected token'。在第一行。有人知道为什么会这样吗,因为我对Node和repl没有太多经验。
答案 0 :(得分:1)
您只能在REPL控制台中使用.load path_to_the_module
命令。要在文件脚本中加载模块,您需要使用require('path_to_the_module')
。
因此transformscript.js
中的第一行应为:
require('./rdfMapping.js');
require('./rdfVocab.js');