Error: Can't find npm module 'moment'

Hi All,

I am trying to deploy a Meteor app to a remote server, but I get the following error. Any ideas please?

Assuming you did a meteor npm install on your deployment server (or you are using something like mup/mupx), are you sure it is in your npm dependencies list?
I sometimes forget to add --save when installing dependencies and later wonder why it’s not working on production…

Thanks. Yes I did try that, but I found out my problem was because I have symbolic links and those files are not being shipped to the server.

That’s good to hear.
If you resolved a problem on your own I suggest to post the solution as
well (just like you just did) so future users that run into similar issues
can profit from your effort.

1 Like

Thanks. I have have worked out the symbolic links links are the problem, but I haven’t fixed and tested it yet. When I do, I will post the answer.

I’m still trying to figure it out. I deployed a version with no symbolic links, but still get:

2016-09-11T15:14:27.269682+00:00 heroku[web.1]: State changed from crashed to starting
2016-09-11T15:14:35.783610+00:00 app[web.1]: /app/.meteor/heroku_build/app/programs/server/node_modules/fibers/future.js:280
2016-09-11T15:14:35.783621+00:00 app[web.1]: 						throw(ex);
2016-09-11T15:14:35.783625+00:00 app[web.1]: 						^
2016-09-11T15:14:35.783625+00:00 app[web.1]: 
2016-09-11T15:14:35.783626+00:00 app[web.1]: Error: Can't find npm module 'moment'. Did you forget to call 'Npm.depends' in package.js within the 'modules-runtime' package?
2016-09-11T15:14:35.783627+00:00 app[web.1]:     at Object.Npm.require (/app/.meteor/heroku_build/app/programs/server/boot.js:198:17)
2016-09-11T15:14:35.783628+00:00 app[web.1]:     at options.fallback (packages/modules-runtime/modules-runtime.js:21:1)
2016-09-11T15:14:35.783629+00:00 app[web.1]:     at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:88:1)
2016-09-11T15:14:35.783629+00:00 app[web.1]:     at meteorInstall.server.main.js (server/main.ts:1:19)
2016-09-11T15:14:35.783630+00:00 app[web.1]:     at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1)
2016-09-11T15:14:35.783631+00:00 app[web.1]:     at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:82:1)
2016-09-11T15:14:35.783632+00:00 app[web.1]:     at server/main.ts:65:4
2016-09-11T15:14:35.895010+00:00 heroku[web.1]: State changed from starting to crashed
2016-09-11T15:14:35.880918+00:00 heroku[web.1]: Process exited with status 1

I have tried: meteor npm install --save

I removed the .gitignore of node_modules/, and I don’t get any errors now.

However, I am new to Meteor, so not sure how to test this. But when I try invoke the app with http://remote-thewhozoo.herokuapp.com/ or https://remote-thewhozoo.herokuapp.com/ I get a 404 error:

2016-09-11T16:20:15.183895+00:00 heroku[router]: at=info method=GET path="/sockjs/info?cb=jwgw2yuvgl" host=remote-thewhozoo.herokuapp.com request_id=a49fafb2-9708-46d2-8117-2c789bfa6a3e fwd="105.186.215.147" dyno=web.1 connect=1ms service=2ms status=404 bytes=132

I tried to install Meteor on OpenShift too, but could not access the server either as on Heroku. Can anyone please advise me because I am new to Meteor?

p.s. Is Meteor notoriously difficult to deploy and get running? I come from a java background and am used to deploying application servers on remote servers which is very simple.

You should definitely not need to do this. In fact you absolutely shouldn’t do this, as you will be pushing unnecessary files up to git.

All required code will be bundled into a single node executable when you do a meteor build on your development machine. It is that bundle which you should deploy to your production server, as it will have no dependencies on anything else.

The easiest way to deploy a Meteor application is onto Galaxy. Then it boils down to a single command:

meteor deploy myappname

Hi Rob,

Thanks for the reply.

Thanks. I was confused about the .gitignore. However, why does my meteor app run locally, but when I deploy it to Heroku, it gets:

2016-09-12T10:02:17.820472+00:00 heroku[web.1]: Starting process with command `.meteor/heroku_build/bin/node .meteor/heroku_build/app/main.js`
2016-09-12T10:02:21.956530+00:00 app[web.1]: /app/.meteor/heroku_build/app/programs/server/node_modules/fibers/future.js:280
2016-09-12T10:02:21.956548+00:00 app[web.1]: 						throw(ex);
2016-09-12T10:02:21.956555+00:00 app[web.1]: Error: Can't find npm module 'moment'. Did you forget to call 'Npm.depends' in package.js within the 'modules-runtime' package?
2016-09-12T10:02:21.956556+00:00 app[web.1]:     at Object.Npm.require (/app/.meteor/heroku_build/app/programs/server/boot.js:198:17)

If I do not deploy node_modules, how do I ensure the moment libraries get moved to the server?

(Sorry, excuse my ignorance. I am pushing everything in the meteor apps root dir. Is this correct?).

p.s. I am just building a proof of concept for now, so don’t want to have to pay (which Galaxy requires).

If by that you mean that is what you are doing to deploy an app … then it’s incorrect.

Check out the meteor build command: Command Line | Meteor API Docs and deployment options: Deployment and Monitoring | Meteor Guide

Yes, that is what I am doing to deploy the app. I am following this guide.

Let me look at the docs you pointed out, perhaps the guide I read is incorrect.

I think the difference is Heroku here. The way I am deploying it, is with a buildpack:

heroku create <appname> --stack cedar --region us --buildpack https://github.com/AdmitHub/meteor-buildpack-horse.git

p.s. I did build a simple hello world example, that deployed successfully to Heroku this way. But I seem to be having problems with the moments library.

I’ve not used Heroku, but if it’s using a git workflow (and is npm aware) the installer should be doing all the module fetching for you as part of the build. Perhaps that buildpack needs updating?

Just a thought - is your package.json being pushed to git (it should be)?

Yes, perhaps the buildpack is out of date. I am confused though, because why is it only complaining about the moment library.

I suppose what I am doing with the build pack is not necessarily what meteor intends.

Have you added in any moment packages from atmosphere, or only from npm?

Does your package.json declare moment as a dependency?

Only from npm.

I do not have a package.json in my meteor app, but I do have a tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  },
  "files": [
    "typings/index.d.ts",
    "node_modules/zone.js/dist/zone.js.d.ts"
  ],
  "exclude": [
    "www",
    "node_modules"
  ]
}

Is this maybe my problem?

In my Ionic app, I do have a package.json that contains "moment": "^2.14.1",.

I admit I don’t understand the structure, I have just copied this tutorial when developing it.

Yeah - you definitely need a package.json - it’s that which defines (among other things) the dependencies your app needs. However, you should have one if you’ve done a meteor npm install (generally the first command you do following creating a new project), and then meteor npm install --save package1 package2 ... as you add npm packages into your project.

Try meteor npm install first and check that package.json has been created and has the required dependencies.

1 Like

Thank you, I will try. I appreciate your help. This is my first time working with Meteor.

1 Like

I added a package.json. I just looked back at the tutorial I was doing, and it said to remove it because it was sharing with the Ionic app. But now because I am deploying it, I am separating it.

package.json

{
  "name": "api",
  "private": true,
  "scripts": {
    "start": "meteor run"
  },
  "dependencies": {
    "meteor-node-stubs": "~0.2.0",
    "moment": "^2.15.0"
  }
}

But I get this error:

2016-09-12T12:26:22.566461+00:00 heroku[slug-compiler]: Slug compilation started
2016-09-12T12:26:22.566467+00:00 heroku[slug-compiler]: Slug compilation finished
2016-09-12T12:26:22.702841+00:00 heroku[web.1]: State changed from crashed to starting
2016-09-12T12:26:30.898335+00:00 heroku[web.1]: Starting process with command `.meteor/heroku_build/bin/node .meteor/heroku_build/app/main.js`
2016-09-12T12:26:33.514696+00:00 heroku[web.1]: Process exited with status 22
2016-09-12T12:26:33.524813+00:00 heroku[web.1]: State changed from starting to crashed
2016-09-12T12:26:33.524813+00:00 heroku[web.1]: State changed from crashed to starting
2016-09-12T12:26:33.421100+00:00 app[web.1]: Error: No such file or directory
2016-09-12T12:26:41.237006+00:00 heroku[web.1]: Starting process with command `.meteor/heroku_build/bin/node .meteor/heroku_build/app/main.js`
2016-09-12T12:26:42.989529+00:00 app[web.1]: Error: No such file or directory
2016-09-12T12:26:42.989812+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2016-09-12T12:26:43.076487+00:00 heroku[web.1]: Process exited with status 22
2016-09-12T12:26:43.109042+00:00 heroku[web.1]: State changed from starting to crashed

Any ideas appreciated.