0

I'm working with Meteor running on localhost:3000.

I used 'npm install require' to install require in the app directory.

As near as I can tell it installed properly. Yet I'm still getting the error...

Exception while invoking method 'zeroMQSend' ReferenceError: require is not defined

I've tried the solutions here:

ReferenceError: Require is not defined (Webstorm)

I believe Meteor is running the node.js server??, so that should be the issue.

I tried this solution here: Uncaught ReferenceError: require is not defined

But the method is defined in the server folder. That shouldn't be the problem either.

Here's the code in the server folder that's invoking the error:

Meteor.methods({
    zeroMQSend: function (sendJson) {
        var zmq = require('zmq');

        var Future = Npm.require("fibers/future");
        var fut = new Future();

        console.log('Sending thru zeroMQ : %s', sendJson);
        var socket = zmq.socket('req');
        socket.connect('tcp://localhost:5555');
        socket.send(sendJson);
        socket.on('message', function(data) {
            console.log('Reply: ' + data);
            fut['return'](data);
        });
        return fut.wait();
    }
});

Here's the code on the client side calling the method:

Template.TrendTrader.events({
    'click #go_button': function () {

        console.log('"go" button clicked');
        var p1_time = trend_p1_time.value;
        var p1_price = trend_p1_price.value;
        var p2_time = trend_p2_time.value;
        var p2_price = trend_p2_price.value;
        console.log('Trend point 1 time: ', p1_time, ' Price: ', p1_price);
        console.log('Trend point 2 time: ', p2_time, ' Price: ', p2_price);

        var trend_line_Json = '{"trend_p1_time": "p1_time", "trend_p1_price": "p1_price",' +
            ' "trend_p2_time": "p2_time", "trend_p2_price": "p2_price"}';

        Meteor.call('zeroMQSend', trend_line_Json);


    }
});

Here's the full error:

20151201-22:41:12.179(2)? Exception while invoking method 'zeroMQSend' ReferenceError: require is not defined
I20151201-22:41:12.179(2)?     at [object Object].Meteor.methods.zeroMQSend (server/methods.js:10:19)
I20151201-22:41:12.179(2)?     at packages/check/match.js:103:1
I20151201-22:41:12.180(2)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151201-22:41:12.180(2)?     at Object.Match._failIfArgumentsAreNotAllChecked (packages/check/match.js:102:1)
I20151201-22:41:12.181(2)?     at maybeAuditArgumentChecks (livedata_server.js:1695:18)
I20151201-22:41:12.181(2)?     at livedata_server.js:708:19
I20151201-22:41:12.181(2)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151201-22:41:12.181(2)?     at livedata_server.js:706:40
I20151201-22:41:12.182(2)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151201-22:41:12.182(2)?     at livedata_server.js:704:46
Community
  • 1
  • 1
Emily
  • 2,129
  • 3
  • 18
  • 43
  • Possible duplicate of [Meteor: ReferenceError: require is not defined](http://stackoverflow.com/questions/27993227/meteor-referenceerror-require-is-not-defined) – Matthias A. Eckhart Dec 01 '15 at 20:48
  • It's not loaded via meteorhacks. I tried the solution anyway. It didn't work. – Emily Dec 01 '15 at 20:53
  • Also, the method is in the server folder. – Emily Dec 01 '15 at 20:55
  • 1
    Try using `Meteor.npmRequire()` instead of `require`. – MasterAM Dec 01 '15 at 21:30
  • I'm not using meteorhacks... but tried it anyway. I'm getting a 404 error when trying to install: 'npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/npmRequire'. Before I try to figure that one out, because I'm not using meteorhacks, will it help me? – Emily Dec 01 '15 at 21:48
  • As MasterAM was saying, you need to run `meteor add meteorhacks:npm`, and then use `Meteor.npmRequire()` instead of `require`. – Christian Fritz Dec 01 '15 at 22:12

0 Answers0