claudiajs / claudia

Deploy Node.js projects to AWS Lambda and API Gateway easily
https://claudiajs.com
MIT License
3.8k stars 274 forks source link

Cannot require ./lambda after clean installation, async await + express #115

Closed Alex-Mann closed 7 years ago

Alex-Mann commented 7 years ago

I am trying to run an express app by following the tutorial outlined here. I am also trying to use async await syntax by transpiling with babel. I have created a bin folder that I transpile a basic express app to. For some reason when I call: claudia create --handler lambda.handler --deploy-proxy-api --region us-east-1 I get the error:

validating package
Error: Cannot find module 'babel-runtime/regenerator'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/private/var/folders/fw/vrbqmjcs7fv3n73q52rw7hnc0000gn/T/dfd3b547-ee80-4f43-979c-71a559167363/app.js:3:20)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
cannot require ./lambda after clean installation. Check your dependencies.

I have tried various setups but am still having no luck. This is what my package.json looks like:


{
  "name": "myapp",
  "version": "0.0.1",
  "description": "nothing",
  "main": "index.js",
  "scripts": {
    "tp": "babel --presets es2015 --plugins async-to-promises myStupidApp --out-dir bin",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Alexander Mann",
  "license": "MIT",
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-core": "^6.24.0",
    "babel-plugin-async-to-promises": "^1.0.5",
    "babel-preset-es2015": "^6.24.1",
    "babel-runtime": "^6.23.0"
  },
  "dependencies": {
    "aws-serverless-express": "^2.2.0",
    "express": "^4.15.2",
    "isomorphic-fetch": "^2.2.1"
  }
}
gojko commented 7 years ago

your lambda function is trying to include a dev dependency for some reason, and the error message is saying that it cannot load it (which is correct, because the package is validated after creating a clean production install). you shouldn't need to have babel dependencies loaded from within the lambda function. alternatively, if you really want to do that for some strange reason, you'll need to include babel-runtime/regenerator as a production dependency.