dcsan
dcsan

Reputation: 12315

with server side meteor, why is "module" not defined?

I'm using some node code that has

module.exports  = a;

which gives:

ReferenceError: module is not defined

then separately what are the recommended workarounds? I'd prefer to have some simple known code than install a package that "magically" makes this work.

how is this the case? does meteor server code somehow run in something is not node? I understand we have fibers wrapping but i didn't think you could "undefine" something that is fundamental to the node environment?

W20150202-16:07:12.555(-8)? (STDERR) /Users/dc/.meteor/packages/meteor-tool/.1.0.40.prjwsp++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:173 W20150202-16:07:12.555(-8)? (STDERR) throw(ex); W20150202-16:07:12.555(-8)? (STDERR) ^ W20150202-16:07:12.596(-8)? (STDERR) ReferenceError: module is not defined W20150202-16:07:12.596(-8)? (STDERR) at __coffeescriptShare (packages/dcsan:ribot/vendor/rivescript-js/lib/rivescript.js:2913:1) W20150202-16:07:12.596(-8)? (STDERR) at RiveScript (packages/dcsan:ribot/vendor/rivescript-js/lib/rivescript.js:2910:1) W20150202-16:07:12.596(-8)? (STDERR) at __coffeescriptShare (packages/dcsan:ribot/vendor/rivescript-js/lib/rivescript.js:2911:1) W20150202-16:07:12.597(-8)? (STDERR) at /Users/dc/dev/shumi/chatU/app/.meteor/local/build/programs/server/packages/dcsan_ribot.js:2937:4 W20150202-16:07:12.597(-8)? (STDERR) at packages/dcsan:ribot/both/startup.coffee:13:23 W20150202-16:07:12.597(-8)? (STDERR) at /Users/dc/dev/shumi/chatU/app/.meteor/local/build/programs/server/boot.js:205:10

Upvotes: 1

Views: 1015

Answers (3)

Quang Le
Quang Le

Reputation: 11

I had the same problem when trying to define Cucumber steps for Chimp. I managed to resolve it by wrapping the module.exports like this:

(function() {
  'use strict';
  module.exports = function() {
    ...
  };
})();

Did that work for you?

Upvotes: 1

greymatter
greymatter

Reputation: 990

I was seeing the same error, and deleting the node_modules directory from my meteor project did the trick.

What has not been made clear in any of the articles or README file is that all you need is the packages.json file. I thought I needed to install the npm's myself, but that is wrong, and those installed npm's conflict with the ones that meteorhacks:npm installs, based on packages.json.

Upvotes: 1

imslavko
imslavko

Reputation: 6676

Meteor uses the vm module to create new contexts. I suspect so does plain node.js too, there is nothing "fundamental" about the keyword module. Under the hood node.js loader wraps all files into closures and passes special variables such as __dirname into them.

http://nodejs.org/api/vm.html

Upvotes: 1

Related Questions