流星找不到模块“模块”

时间:2014-02-04 23:23:46

标签: meteor

我正在尝试在meteor中安装Spooky模块(这个模块位于我的公共文件夹中:app / public / node_modules)。

我已阅读答案in this post并在server / server.js

中添加了以下代码
Meteor.startup ->
    path = Npm.require 'path'
    fs = Npm.require 'fs'
    base = path.resolve '.'
    isBundle = fs.existsSync base + '/bundle'
    modulePath = base + (if isBundle then '/bundle/static' else '/public') + '/node_modules'
    spooky = Npm.require modulePath + '/spooky'

但是当我运行流星时,我得到了:

Error: Cannot find module '/Users/mac/Documents/websites/app/.meteor/local/build/programs/server/public/node_modules/spooky'

2 个答案:

答案 0 :(得分:1)

您需要创建一个智能包才能在您的应用中使用Npm模块。或者你可以使用meteor-npm。

您不能将Npm.require用于非标准的npm模块,例如幽灵般的。

如果你使用meteor-npm,可以用陨石安装它:mrt add npm

然后在将模块添加到packages.json之后使用Meteor.require("spooky")。您可以在此处查看详细信息:http://meteorhacks.com/complete-npm-integration-for-meteor.html

这样做的官方方法是制作自己的智能包来包装npm模块。有一个这样的包的例子:https://github.com/avital/meteor-xml2js-npm-demo

该示例使用xml2js作为npm模块,但您可以交换名称,因此它的怪异而不是。

然后,您可以将此包添加到/packages文件夹中(例如名称为spooky),并使用meteor add spooky将其添加到您的流星项目中。

在atmosphere.meteor.com上的软件包有更多的例子,他们几乎做同样的事情(例如stripe(https://atmosphere.meteor.com/package/stripe))。

答案 1 :(得分:0)

The article Akshat linked to已更新:

cd project
meteor add meteorhacks:npm

修改project/packages.json

{
  "redis": "0.8.2",
  "github": "0.1.8"
}

使用那些npm模块:

var Github = Meteor.npmRequire('github');
var github = new Github();

github.gists.getFromUser({user: 'arunoda'}, function(err, gists) {
  console.log(gists);
});
相关问题