Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'require is not defined' in Meteor.js when including NPM package

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');

Error

ReferenceError: require is not defined

The npm package has lines such as

var https = require('https')
var url = require('url')
var crypto = require('crypto')

Must the package's code be manually edited to use Npm.require? Editing them manually got rid of the errors.

However theres a line:

module.exports = SOMETHING

How should we call module from within meteor?

like image 701
Nyxynyx Avatar asked Dec 06 '22 04:12

Nyxynyx


1 Answers

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.

The monkey-patching of the Meteor global by this package is misleading.

like image 80
Andrew Mao Avatar answered Jan 25 '23 23:01

Andrew Mao