How can I deploy node modules in a Meteor application on meteor.com?

I have an application that uses the node twit module, which is accessible through

npm install twit 

I deployed the node module locally from .meteor / local / assemblies / server /

So it is visible on .meteor / local / assemblies / server / node_modules / cretin

I tried to install it in the root of the project, but the project did not find the module. This led me to the solution described above.

My application now works fine locally. I can run and do everything and interact with Twitter from the Meteor server side or from the client side, depending on what I want to do. No glitches.

When I deploy to meteor.com through the team

 meteor deploy [appname] --password 

The application is successfully deployed.

When I try to access (anonistream.meteor.com) (anonistream.meteor.com) from the browser, it fails and the logs contain this error.

 [Mon May 07 2012 01:59:53 GMT+0000 (UTC)] WARNING node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ Error: Cannot find module 'twit' at Function._resolveFilename (module.js:332:11) at Function._load (module.js:279:25) at Module.require (module.js:354:17) at require (module.js:370:17) at app/server/server.js:2:12 at /meteor/containers/84162a7c-24e8-bf26-6fd8-e4ec13b2a935/bundle/server/server.js:111:21 at Array.forEach (native) at Function.<anonymous> (/meteor/containers/84162a7c-24e8-bf26-6fd8- e4ec13b2a935/bundle/server/underscore.js:76:11) at /meteor/containers/84162a7c-24e8-bf26-6fd8-e4ec13b2a935/bundle/server/server.js:97:7 [Mon May 07 2012 01:59:53 GMT+0000 (UTC)] INFO STATUS running -> waiting [Mon May 07 2012 01:59:53 GMT+0000 (UTC)] ERROR Application crashed with code: 1 [Mon May 07 2012 02:29:55 GMT+0000 (UTC)] INFO HIT / 24.94.158.145 [Mon May 07 2012 02:29:59 GMT+0000 (UTC)] INFO HIT /favicon.ico 24.94.158.145 [Mon May 07 2012 02:30:46 GMT+0000 (UTC)] INFO HIT / 24.94.158.145 [Mon May 07 2012 02:30:50 GMT+0000 (UTC)] INFO HIT /favicon.ico 24.94.158.145 

Does anyone have any suggestions on how to do this?

+19
meteor
May 7 '12 at 2:55 a.m.
source share
7 answers
Finally, I wrote this. It works on both local and meteor ports. thanks Ian: D

install the npm module inside "app / public":

     app / public # npm install MODULE_NAME

inside app / server / server.js:

 Meteor.startup(function () { var require = __meteor_bootstrap__.require; var path = require('path'); var base = path.resolve('.'); var isBundle = path.existsSync(base + '/bundle'); var modulePath = base + (isBundle ? '/bundle/static' : '/public') + '/node_modules'; var MODULE_NAME = require(modulePath + '/MODULE_NAME'); }); 
+8
04 Oct
source share

Starting with Meteor 6.0, now we need to use Npm.require (). In addition, we must declare the module global variables, since Meteor now has a file-level scope.

  var path = Npm.require('path'); var fs = Npm.require('fs'); var base = path.resolve('.'); var isBundle = fs.existsSync(base + '/bundle'); var modulePath = base + (isBundle ? '/bundle/static' : '/public') + '/node_modules'; MODULE_NAME = Npm.require(modulePath + '/MODULE_NAME'); // NOTE, this is going to be a global variable 
+14
Jun 30 '13 at 23:57
source share

The answer to this question is JonathanKingston from meteor irc. Link to meteorite project

Put the node modules in the shared project directory.

Use this code so that it loads.

 var require = __meteor_bootstrap__.require; var path = require("path"); var fs = require('fs'); var Twit; var twitPath = 'node_modules/twit'; var base = path.resolve('.'); if (base == '/'){ base = path.dirname(global.require.main.filename); } var publicPath = path.resolve(base+'/public/'+twitPath); var staticPath = path.resolve(base+'/static/'+twitPath); if (path.existsSync(publicPath)){ Twit = require(publicPath); } else if (path.existsSync(staticPath)){ Twit = require(staticPath); } else{ console.log('node_modules not found'); } 

Meteor deployment should work after this, force me to host my node modules on the dirs server

+7
May 08 '12 at 9:51 am
source share

I just spent half an hour figuring out “install the npm module inside the app/public step and thought that I would save the next person for a while. From the application’s home directory:

 cd public mkdir node_modules npm install foo 

By default, npm install foo installs "locally", but if your current directory does not have node_modules , then it moves up the directory tree looking for it. As a result, I installed the $HOME/node_modules/foo package instead of the local project. Fine for localhost , but not so much for deployment.

(Thanks to npm install locally to solve my main problem.)

+4
Oct 27 '13 at 11:35 on
source share

This code worked for me with installing meteor 0.8.x and node_modules in. / public of my application:

 var path = Npm.require('path') var fs = Npm.require('fs') var base = path.resolve('.') var isBundle = fs.existsSync(base + '/bundle') var modulePath = base + (isBundle ? '/bundle/static' : '/../client/app') + '/node_modules/' var twit = Npm.require(modulePath+'rssparser') 

It might also be a good idea to create a packages.json file inside. / public to simplify updating / installation through npm.

Long live the Meteor!

+2
Jun 05 '14 at 1:41
source share

Modified by:

 var modulePath = base + (isBundle ? '/bundle/static' : '/../client/app') + '/node_modules/' 

at

 var modulePath = base + (isBundle ? '/bundle/static' : '/../web.browser/app') + '/node_modules/' 
+1
Nov 17 '15 at 23:27
source share

You

 base = base + "/bundle" 

to make it work.

0
Aug 14 '12 at 3:32
source share



All Articles