运行 nodejs Thrift 示例时未找到对 Thrift 的引用
Reference to Thrift not found when running nodejs Thrift example
我正在尝试 运行 nodejs server/client thrift 示例,但我无法 运行。最初,我在 package.json
文件中添加了 thrift 作为依赖项。然后我做了一个 npm install
安装节俭。然后我尝试使用 node NodeServer.js
运行 服务器。当我尝试 运行 NodeClient.js
.
时出现类似的错误
Link 到 Thrift nodejs 教程 - http://thrift.apache.org/tutorial/nodejs
我在下面附上了相关命令的输出。
h@h-vbox:~/git/nodejs-thrift$ ls
gen-js NodeClient.js NodeServer.js package.json shared.thrift tutorial.thrift
h@h-vbox:~/git/nodejs-thrift$ npm install
> ws@0.4.32 install /home/h/git/nodejs-thrift/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)
make: Entering directory '/home/h/git/nodejs-thrift/node_modules/ws/build'
CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
bufferutil.target.mk:92: recipe for target 'Release/obj.target/bufferutil/src/bufferutil.o' failed
make: Leaving directory '/home/h/git/nodejs-thrift/node_modules/ws/build'
nodethrift-server@0.0.1 /home/h/git/nodejs-thrift
└─┬ thrift@0.9.3
├── node-int64@0.3.3
├── q@1.0.1
└─┬ ws@0.4.32
├── commander@2.1.0
├── nan@1.0.0
├── options@0.0.6
└── tinycolor@0.0.1
npm WARN nodethrift-server@0.0.1 No description
npm WARN nodethrift-server@0.0.1 No repository field.
npm WARN nodethrift-server@0.0.1 No license field.
h@h-vbox:~/git/nodejs-thrift$ node NodeServer.js
/home/h/git/nodejs-thrift/gen-js/Calculator.js:384
Thrift.inherits(CalculatorClient, SharedServiceClient)
^
ReferenceError: Thrift is not defined
at Object.<anonymous> (/home/h/git/nodejs-thrift/gen-js/Calculator.js:384:1)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/h/git/nodejs-thrift/NodeServer.js:21:18)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
h@h-vbox:~/git/nodejs-thrift$
事实证明,我使用 js
标志而不是 js:node
标志生成我的 thrift 文件是一个错误。生成这些文件的正确方法是,
thrift -r --gen js:node tutorial.thrift
我正在尝试 运行 nodejs server/client thrift 示例,但我无法 运行。最初,我在 package.json
文件中添加了 thrift 作为依赖项。然后我做了一个 npm install
安装节俭。然后我尝试使用 node NodeServer.js
运行 服务器。当我尝试 运行 NodeClient.js
.
Link 到 Thrift nodejs 教程 - http://thrift.apache.org/tutorial/nodejs
我在下面附上了相关命令的输出。
h@h-vbox:~/git/nodejs-thrift$ ls
gen-js NodeClient.js NodeServer.js package.json shared.thrift tutorial.thrift
h@h-vbox:~/git/nodejs-thrift$ npm install
> ws@0.4.32 install /home/h/git/nodejs-thrift/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)
make: Entering directory '/home/h/git/nodejs-thrift/node_modules/ws/build'
CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
bufferutil.target.mk:92: recipe for target 'Release/obj.target/bufferutil/src/bufferutil.o' failed
make: Leaving directory '/home/h/git/nodejs-thrift/node_modules/ws/build'
nodethrift-server@0.0.1 /home/h/git/nodejs-thrift
└─┬ thrift@0.9.3
├── node-int64@0.3.3
├── q@1.0.1
└─┬ ws@0.4.32
├── commander@2.1.0
├── nan@1.0.0
├── options@0.0.6
└── tinycolor@0.0.1
npm WARN nodethrift-server@0.0.1 No description
npm WARN nodethrift-server@0.0.1 No repository field.
npm WARN nodethrift-server@0.0.1 No license field.
h@h-vbox:~/git/nodejs-thrift$ node NodeServer.js
/home/h/git/nodejs-thrift/gen-js/Calculator.js:384
Thrift.inherits(CalculatorClient, SharedServiceClient)
^
ReferenceError: Thrift is not defined
at Object.<anonymous> (/home/h/git/nodejs-thrift/gen-js/Calculator.js:384:1)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/h/git/nodejs-thrift/NodeServer.js:21:18)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
h@h-vbox:~/git/nodejs-thrift$
事实证明,我使用 js
标志而不是 js:node
标志生成我的 thrift 文件是一个错误。生成这些文件的正确方法是,
thrift -r --gen js:node tutorial.thrift