简体   繁体   中英

Using an NPM package with dependencies in Meteor

I'm trying to use an NPM package in my meteor project but I have some problems getting it to work.

The module I'm trying to use is this steam package. I've added the meteorhacks:npm package for meteor and changed the packages.json file to:

{
  "steam": "0.6.8",
    "adm-zip": "0.4.7",
    "buffer-crc32": "0.2.5",
    "bytebuffer": "3.5.4",
      "bufferview": "1.0.1",
      "long": "2.2.3",
    "protobufjs": "4.0.0-b2",
      "ascli": "1.0.0",
        "optjs": "3.2.1-boom",
      "colour": "0.7.1"
}

(to clarify the above, it's the steam package with all its dependencies and the dependencies of the dependencies)

Now I've tried to use the package in my meteor app with this code located in -/server/steambot/steambot.js

var Steam = Meteor.npmRequire('steam');
var bot = new Steam.SteamClient();
bot.logOn({  // (fake credentials)
    accountName: 'a', 
    password: '123456789',
    authCode: 'aaa55',
    shaSentryfile: 'aaa'
});

I hoped it would be as easy as that but then the errors started.

var cryptedSessKey = require('crypto').publicEncrypt(fs.readFileSync(__dirna TypeError: Object # has no method 'publicEncrypt'

I figured out it's the require() function of the steam and dependencie packages that's giving me these errors. If I replace the require() with Meteor.npmRequire() I just go the the next require() function in one of the NPM packages.

Is there a way to fix this issue without changing every require() function to Meteor.npmRequire() ?

And even if I should what is the best approach?

I'm also quite new to the NPM and Meteor world, is this kind of workflow the way I should be doing it and/or are there any improvements I could make or keep in mind?

Update: As of July 2016 Meteor 1.4 uses Node 4.4.7, which does support the stream npm package (requires 4.1.1+)

The Steam NPM plugin will not work with Meteor.

The NPM package page ( https://www.npmjs.com/package/steam ) states:

Note: only Node.js v0.12 and io.js v1.4 are supported.

Meteor is using an older version of NodeJS. Eg Meteor v1.0.4 (March 17, 2015) uses v0.10.36

Meteor has very short release cycles, but I doubt that Node v0.12 will be supported anytime soon considering that Meteor v0.8.1.1 (May 1, 2014) was using Node v0.10.26.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM