包含NPM包时,Meteor.js中的'require is not defined' [英] 'require is not defined' in Meteor.js when including NPM package
问题描述
我正在尝试使用来自Meteor.js (版本0.6.6.3)的npm包,使用 Meteor.require
。但是,它会抛出错误,指出 require
未定义。为什么这个以及我们如何解决它?
I'm trying to use a npm package from Meteor.js (Release 0.6.6.3) using Meteor.require
. However it throws an error saying that require
is not defined. Why is this and how can we solve it?
mrt add npm
npm install github
packages.json
{
"github": "0.1.8"
}
github.js
var GITHUB = Meteor.require('github');
错误
ReferenceError: require is not defined
npm包包含诸如
The npm package has lines such as
var https = require('https')
var url = require('url')
var crypto = require('crypto')
必须手动编辑包的代码才能使用 Npm.require
?手动编辑它们可以消除错误。
Must the package's code be manually edited to use Npm.require
? Editing them manually got rid of the errors.
但是有一行:
module.exports = SOMETHING
我们应如何调用模块流星内的code>?
推荐答案
Meteor.require
是由 meteor npm智能包添加的功能,实际上对使用npm没有太大帮助包装一些异步回调。它已经有几个月了,所以你可能想直接尝试使用Meteor的 Npm.require
以防万一有什么事情发生。
Meteor.require
is a function added by the meteor npm smart package, which actually doesn't do much for using npm other than wrapping some asynchronous callbacks. It's a few months old, so you might want to try using Meteor's Npm.require
directly in case something broke.
通过此程序包对 Meteor
全球进行猴子修补是误导性的。
The monkey-patching of the Meteor
global by this package is misleading.
这篇关于包含NPM包时,Meteor.js中的'require is not defined'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!