在Meteor.JS应用程序中,安装了iron:router;我无法加载NPM模块" opennebula" (可从https://github.com/OpenNebula/addon-nodejs)到我的项目中(在服务器端);我收到堆栈跟踪如下:
I20150222-03:56:59.927(-5)? Exception while invoking method 'onLoad' Error: Cannot find module '/usr/local/lib/node_modules/opennebula'
I20150222-03:56:59.928(-5)? at Function.Module._resolveFilename (module.js:338:15)
I20150222-03:56:59.928(-5)? at Function.Module._load (module.js:280:25)
I20150222-03:56:59.928(-5)? at Module.require (module.js:364:17)
I20150222-03:56:59.928(-5)? at require (module.js:380:17)
I20150222-03:56:59.928(-5)? at Object.Npm.require (/root/app/.meteor/local/build/programs/server/boot.js:129:18)
I20150222-03:56:59.929(-5)? at [object Object].Meteor.methods.onLoad (app/server/__main__.js:6:28)
I20150222-03:56:59.929(-5)? at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1599:1)
I20150222-03:56:59.929(-5)? at packages/ddp/livedata_server.js:648:1
I20150222-03:56:59.929(-5)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150222-03:56:59.929(-5)? at packages/ddp/livedata_server.js:647:1
指定的模块路径实际上包含从NPM安装的模块:
fox2 ~ # ls /usr/local/lib/node_modules/opennebula
./ ../ lib/ node_modules/ .npmignore package.json README.md test/
因此,我的server/__main__.js
文件包含以下代码:
if (Meteor.isServer){
Meteor.methods({
'onLoad': function(){
var OpenNebula = Npm.require('/usr/local/lib/node_modules/opennebula'); // <== THIS LINE
var one = new OpenNebula("user:pass", "http://127.0.0.1:2633/RPC2");
one.version(function(err, data) {
console.log(data);
});
return "Survey says...";
}
})
}
调用此函数的客户端代码如下:
if (Meteor.isClient) {
callback = function(a){
console.log('callback: ' + a);
};
Meteor.call('onLoad', callback);
}
meteor app的软件包和版本如下:
fox2 app # meteor update
This project is already at Meteor 1.0.3.1, the latest release.
Your packages are at their latest compatible versions.
fox2 app # meteor list
autopublish 1.0.2 Publish the entire database to all clients
insecure 1.0.2 Allow all database writes by default
iron:router 1.0.7 Routing specifically designed for Meteor
jquery 1.11.3 Manipulate the DOM using CSS selectors
meteor-platform 1.2.1 Include a standard set of Meteor packages in your app
我做错了什么?
我发现这个模块甚至不能在Node.JS中工作:
fox2 Standalone # node -v
v0.12.0
fox2 Standalone # node __main__.js
module.js:338
throw err;
^
Error: Cannot find module 'opennebula'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/root/Standalone/__main__.js:1:80)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
答案 0 :(得分:0)
原来,答案是:
我提出了一个拉取请求(PR#3)来解决此问题。