claudiajs / claudia

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

cannot require ./lambda after clean installation. Check your dependencies. #132

Closed raphaelcrv closed 7 years ago

raphaelcrv commented 7 years ago

annot find module 'C:\Users\Raphael\AppData\Local\Temp\51ad0ddd-0f56-4683-888e-8f68d4474064\lambda image

I'm following the doc Deploying your first AWS Lambda function

gojko commented 7 years ago

this is not a bug, your lambda handler doesn't compile or you've not specified the correct lambda handler. check the error message at the bottom of the screen (cannot require ./lambda after clean installation). I suggest trying to load node and use require('./lambda') in your main project dir to check for errors. if that works, it might be trying to instantiate something that's a dev dependency (not a prod dependency). if it doesn't work, it will point out the syntax error

sschadwick commented 6 years ago

Had this exact issue. The problem for me was that main in package.json was not pointing to the lambda but instead the express app.js.

"main": "lambda.js",
omatrot commented 6 years ago

I have the same problem. I've structured my project with a "src" and a "dist" directories, because I'm transpiling code. In my case the app.js file is not located a the root directory (ie: /var/folders/j4/1kkh8y8s6t33r75g56vtfqbh0000gp/T/606fe51e-4fc5-43ab-a6fc-ae458522f5fb/) but in the "dist" subdirectory.

An extract from my package.json file:

  "files": ["dist"],
  "description": "A typescript claudiajs api gateway lambda",
  "main": "app.js",
jmeberst commented 6 years ago

It took me a bit to work this out, so I hope this can help someone else who has this issue.

lambda.js

'use strict';
var awsServerlessExpress = require('aws-serverless-express');
var app = require('./dist/app');
var binaryMimeTypes = ['application/octet-stream', 'font/eot', 'font/opentype', 'font/otf', 'image/jpeg', 'image/png', 'image/svg+xml'];
var server = awsServerlessExpress.createServer(app, null, binaryMimeTypes);
exports.handler = function (event, context) {
    return awsServerlessExpress.proxy(server, event, context);
};
package.json

"files": [ "dist" ]
 "main": "lambda.js",
  "scripts": {
    "transpile": "babel src --out-dir dist",
    "update": "npm run transpile && claudia update",
    "test": "jest"
  }
ceefour commented 5 years ago

I got the same issue, but my problem is that claudia is looking for ./index instead of ./lambda. Why is this?

I tried setting "main": "lambda.js" in package.json but it has no effect.

sschadwick commented 5 years ago

@ceefour What are the Claudia commands you’re using? Anything with index.handler? If so change it to lambda.handler.

anthonyawuley commented 5 years ago

In my case, i was getting this error because my lambda function file is listed in .gitignore. I hope this helps.

This took me hours to find out, the folks at @Claudia.js should investigate this.

tleite commented 5 years ago

Had the same issue.

My setup was:

My fix was the following:

In the app.js, I was missing "module.exports = app" at the very end of the file

alfiepoleon commented 4 years ago

Had a similar error, figured if I try to require a file that is in .gitignore, it throws the error. If I remove the entry from .gitignore, it works as expected. I am now forced to commit a key file I'd rather not.