Error: Unable to find module 'opennebula' (Meteor.JS)

Error: Unable to find module 'opennebula' (Meteor.JS)

我已经尝试过 meteorhacks:npm,但出现了同样的错误。

在 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);
}

流星应用程序包及版本如下:

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)

原来答案是:

  • OpenNebula 制作了一个糟糕的 NPM(节点包)。

我提交了一个拉取请求 (PR#3) 来解决这个问题。