Meteor Galaxy Error : Cannot find module 'aws-sdk'

I am using aws-sdk on Server side to delete some data from S3. I have added the npm module in my project using
meteor npm install --save 'aws-sdk'
in my project. My package.json shows “aws-sdk”: “^2.5.4” as a dependency. Everything works fine in my method ‘deleteImageFromS3’ when I run on localhost. I checked it successfully deletes the image from S3 bucket.

But when I deploy my app on galaxy servers from meteor and I get following error in the logs:

2016-08-31 14:04:02+05:30Exception while invoking method 'deleteImageFromS3' Error: Cannot find module 'aws-sdk'
8j2j
2016-08-31 14:04:02+05:30 at Function.Module._resolveFilename (module.js:325:15)
8j2j
2016-08-31 14:04:02+05:30 at Function.Module._load (module.js:276:25)
8j2j
2016-08-31 14:04:02+05:30 at Module.require (module.js:353:17)
8j2j
2016-08-31 14:04:02+05:30 at require (internal/module.js:12:17)
8j2j
2016-08-31 14:04:02+05:30 at Object.Npm.require (/app/bundle/programs/server/boot.js:166:18)
8j2j
2016-08-31 14:04:02+05:30 at Object.Meteor.npmRequire (packages/npm-container/index.js:2:1)
8j2j
2016-08-31 14:04:02+05:30 at [object Object].deleteImageFromS3 (server/startup/server.js:111:22)

What do I need to do to install aws-sdk on galaxy meteor hosting? I suppose meteor should have taken care of this while building the package before deploying it to meteor hosted galaxy servers. I am using:

Meteor: 1.4.1.1, Node: 4.5.0

Any suggestions as of how to fix this?

Please paste your package.json here.

Here is my Pacakge.json

{
“name”: “shuchimuley”,
“version”: “1.0.0”,
“description”: “Shuchi Muley’s art portfolio website”,
“main”: “index.js”,
“directories”: {
“test”: “tests”
},
“dependencies”: {
“aws-sdk”: “^2.5.4”,
“bcrypt”: “^0.8.7”,
“ev-emitter”: “^1.0.3”,
“imagesloaded”: “^4.1.1”,
“jquery”: “^3.1.0”,
“masonry-layout”: “^4.1.1”,
“meteor-node-stubs”: “^0.2.3”
},
“devDependencies”: {},
“scripts”: {
“test”: “echo “Error: no test specified” && exit 1”
},
“repository”: {
“type”: “git”,
“url”: “git+https://github.com/mintingworks/artgrub.git”
},
“keywords”: [
“artgrub”,
“shuchi”,
“muley”,
“shuchimuley”,
“art”
],
“author”: “Saurabh Shrivastava”,
“license”: “ISC”,
“bugs”: {
“url”: “https://github.com/mintingworks/artgrub/issues
},
“homepage”: “https://github.com/mintingworks/artgrub#readme
}

That looks ok. Have you tried doing a fresh install of your app locally, then running Meteor in production mode?

  1. Copy your project to, for example, /tmp/myproj
  2. cd /tmp/myproj
  3. rm -rf node_modules && meteor reset
  4. meteor npm install
  5. meteor --production (or if you have a settings file: meteor --production --settings settings.json)

See if you get the same error you do in Galaxy.

@ffxsam I followed your steps and my code works in a fresh install. I was able to delete the image and no error was found related to missing ‘aws-sdk’. My problem persists - still getting Cannot find module 'aws-sdk’ on Galaxy.

Do you see any additional information in the Galaxy logs?

Also Galaxy has a support option, try asking the support also maybe. They know more about Galaxy internals.

Already asked the support - their response time is 2 working days. I see successful installation commands and final message that ‘Successfully built the application’. The moment my deleteImageFromS3 method runs it throws error - Cannot find module ‘aws-sdk’

2016-08-31 14:27:18+05:30 ---> aa62fc7a886a
v004
2016-08-31 14:27:19+05:30Removing intermediate container c7e95c0e708a
v004
2016-08-31 14:27:19+05:30Successfully built aa62fc7a886a
v004
2016-08-31 14:27:19+05:30Pushing image to Galaxy's Docker registry.
v004
2016-08-31 14:27:39+05:30Cleaning up.
v004
2016-08-31 14:27:40+05:30Successfully built version 4.
eza2
2016-08-31 14:28:01+05:30Application process starting, version: 4 on apprunner (embedded)
8j2j
2016-08-31 14:28:18+05:30Exception while invoking method 'deleteImageFromS3' Error: Cannot find module 'aws-sdk'
8j2j
2016-08-31 14:28:18+05:30 at Function.Module._resolveFilename (module.js:325:15)
8j2j
2016-08-31 14:28:18+05:30 at Function.Module._load (module.js:276:25)
8j2j
2016-08-31 14:28:18+05:30 at Module.require (module.js:353:17)
8j2j
2016-08-31 14:28:18+05:30 at require (internal/module.js:12:17)
8j2j
2016-08-31 14:28:18+05:30 at Object.Npm.require (/app/bundle/programs/server/boot.js:166:18)
8j2j
2016-08-31 14:28:18+05:30 at Object.Meteor.npmRequire (packages/npm-container/index.js:2:1)
8j2j
2016-08-31 14:28:18+05:30 at [object Object].deleteImageFromS3 (server/startup/server.js:111:22)
8j2j
2016-08-31 14:28:18+05:30 at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1711:12)
8j2j
2016-08-31 14:28:18+05:30 at packages/ddp-server/livedata_server.js:711:19
8j2j
2016-08-31 14:28:18+05:30 at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
8j2j

I found the problem - but not sure about the root cause why it worked on my mac vs galaxy. I was using

Meteor.npmRequire('aws-sdk');

I changed it to
import AWS from 'aws-sdk'; and it worked. Now I can delete images on S3 without any error from galaxy.

Thank you @ffxsam @lucfranken for your input.

1 Like

Likely: It is because this package was for Meteor 1.2:

Now you don’t need it anymore because Meteor now has support for NPM by itself. So you can also remove the meteorhacks:npm package you have been using before.

If you use that aws-sdk in a package you might want to include it in the package with https://docs.meteor.com/api/packagejs.html#Npm-depends instead of globally.

I was about to ask to see the code next. :slight_smile: Yes, Meteor.npmRequire is way deprecated.