3

I created a lambda function through the aws-amplify CLI by following an AWS workshop (https://amplify-workshop.go-aws.com/70_generating_thumbnails/10_creating_a_photo_processor_lambda.html). Seems that there is a problem with conflicting versions of Node.js somewhere.

I believe that the sharp library is the problem, so I have tried to change the version to the latest to see if that would do anything, but it did not fix the issue.

CloudWatch error log:

module initialization error: Error
was compiled against a different Node.js version using
NODE_MODULE_VERSION 67. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at Object.Module._extensions..node (module.js:681:18)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/node_modules/sharp/lib/constructor.js:10:15)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)

I believe there is a simple fix, but I am unsure where the source of the problem lies. Thank you.

7
  • what node version are you using? lambda only supports Node.js 6.10 and 8.10. docs.aws.amazon.com/lambda/latest/dg/programming-model.html Commented Jan 22, 2019 at 1:00
  • My Lambda function is using v8.10, sorry that I forgot to mention that. As NODE_MODULE_VERSION_67 relates to Node.js version 11, I am wondering where that is coming from? The sharp library? Commented Jan 22, 2019 at 1:04
  • 1
    You might be bundling from local system, which probably has node 11 installed. Commented Jan 22, 2019 at 1:05
  • Also possible duplicate of stackoverflow.com/questions/46384591/… Commented Jan 22, 2019 at 1:05
  • Change your local node version to 8.10, remove node_modules, npm install, bundle folder including node_modules and upload to lambda. it should work. Commented Jan 22, 2019 at 1:08

4 Answers 4

6

Use your aws lambda node version when installing sharp.

rm -rf node_modules/sharp
npm install --arch=x64 --platform=linux --target=10.4.1 sharp
Sign up to request clarification or add additional context in comments.

Comments

3

Looks like you have built your node_modules using lambda incompatible version of Node.js. Lambda only supports Node.js 6.10 and 8.10.

Try changing your local node version to 8.10, remove node_modules, npm install, bundle folder including node_modules and upload to lambda. This should work.

Comments

2

I know this question is old. I had the same trouble and discovered the issue is when we build the project (layer) in windows machine and try to run it in lambda. The dependencies built in Linux and Windows environments are different.

Try building & creating the zip file in a linux environment. That should fix your issue.

Windows & Linux node_modules for Sharp

Comments

1

The following worked for me:

npm_config_arch=x64 npm_config_platform=linux npm install sharp

For some reason, arguments did not work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.