简体   繁体   English

在Meteor中使用具有依赖关系的NPM包

[英]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. 我正在尝试在我的流星项目中使用NPM包,但是我在使用它时遇到了一些问题。

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: 我已经为meteor添加了meteorhacks:npm包,并将packages.json文件更改为:

{
  "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) (为了澄清上面的内容,它是具有所有依赖项和依赖项依赖项的steam包)

Now I've tried to use the package in my meteor app with this code located in -/server/steambot/steambot.js 现在我尝试在我的meteor应用程序中使用此代码位于 - / 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' var cryptedSessKey = require('crypto')。publicEncrypt(fs.readFileSync(__ dirna TypeError:Object#没有方法'publicEncrypt'

I figured out it's the require() function of the steam and dependencie packages that's giving me these errors. 我发现它是steam和dependencie包的require()函数,它给了我这些错误。 If I replace the require() with Meteor.npmRequire() I just go the the next require() function in one of the NPM packages. 如果我用Meteor.npmRequire()替换require() ,我只next require()在其中一个NPM包中使用next require()函数。

Is there a way to fix this issue without changing every require() function to Meteor.npmRequire() ? 有没有办法解决这个问题,而不Meteor.npmRequire() 每个require()函数更改为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? 我对NPM和Meteor世界也很陌生,这种工作流程是我应该做的和/或是否有任何改进我可以做或记住?

Update: As of July 2016 Meteor 1.4 uses Node 4.4.7, which does support the stream npm package (requires 4.1.1+) 更新:截至2016年7月,Meteor 1.4使用Node 4.4.7,它支持流npm包(需要4.1.1+)

The Steam NPM plugin will not work with Meteor. Steam NPM插件不适用于Meteor。

The NPM package page ( https://www.npmjs.com/package/steam ) states: NPM包页面( https://www.npmjs.com/package/steam )指出:

Note: only Node.js v0.12 and io.js v1.4 are supported. 注意:仅支持Node.js v0.12和io.js v1.4。

Meteor is using an older version of NodeJS. Meteor正在使用旧版本的NodeJS。 Eg Meteor v1.0.4 (March 17, 2015) uses v0.10.36 例如Meteor v1.0.4(2015年3月17日)使用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. Meteor的发布周期非常短,但我怀疑,鉴于Meteor v0.8.1.1(2014年5月1日)使用的是Node v0.10.26,很快就会支持Node v0.12。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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