是可能的内流星使用的node.js包作为described here,然而由于require
没有全局定义的,具有传递依赖(如例如xml2js或AWS-IIb)的上如何与如何使用与Meteor有传递依赖关系的node.js库?
ReferenceError: require is not defined
任何想法破包修复或解决此问题而不更改库?
是可能的内流星使用的node.js包作为described here,然而由于require
没有全局定义的,具有传递依赖(如例如xml2js或AWS-IIb)的上如何与如何使用与Meteor有传递依赖关系的node.js库?
ReferenceError: require is not defined
任何想法破包修复或解决此问题而不更改库?
我按照linked question的指示操作。我使用node-xml2js库以test fixture from the code base进行测试,并通过以下方式实现。
Meteor.startup(function() {
// This solves the issue
var require = __meteor_bootstrap__.require;
// The example from node-xml2js readme
var fs = require('fs'),
xml2js = require('xml2js');
var parser = new xml2js.Parser();
fs.readFile('/home/prashant/order.xml', 'utf8', function(err, data) {
parser.parseString(data, function (err, result) {
console.log(result);
console.log('Done');
});
});
});
我认为,关键是要定义一个变量require
并将其分配给流星的需要的功能。当Meteor加载服务器资产时,它也会加载require
并解决传递依赖关系的问题。我没有更改node-xml2js库。
希望这会有所帮助!
在最新版本的流星(0.6.3,推测是起),你需要使用Npm.require()
而不是require()
本身。
也看看这里:http://stackoverflow.com/questions/10587964/where-do-we-put-node-modules-we-install-by-npm-in-a-meteor-project – Joscha 2012-08-29 06:31:39