Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
raphaelcrv opened this issue Sep 6, 2017 · 9 comments

Comments

@raphaelcrv
Copy link

raphaelcrv commented Sep 6, 2017

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

@raphaelcrv raphaelcrv changed the title annot find module 'C:\Users\Raphael\AppData\Local\Temp\51ad0ddd-0f56-4683-888e-8f68d4474064\lambda cannot require ./lambda after clean installation. Check your dependencies. Sep 6, 2017
@gojko
Copy link
Member

gojko commented Sep 6, 2017

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

@gojko gojko closed this as completed Sep 6, 2017
@sschadwick
Copy link
Contributor

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
Copy link

omatrot commented Feb 11, 2018

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
Copy link

jmeberst commented Mar 4, 2018

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
Copy link

ceefour commented Dec 27, 2018

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
Copy link
Contributor

sschadwick commented Dec 27, 2018

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

@anthonyawuley
Copy link

anthonyawuley commented Feb 21, 2019

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
Copy link

tleite commented Apr 3, 2019

Had the same issue.

My setup was:

  • on package.json the "main" property was "lambda.js"
  • lambda.js is requiring app.js

My fix was the following:

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

@alfiepoleon
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants