2

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.

ElektrikSpark
  • 493
  • 1
  • 6
  • 20
  • what node version are you using? lambda only supports `Node.js` `6.10` and `8.10`. https://docs.aws.amazon.com/lambda/latest/dg/programming-model.html – Ganapati V S Jan 22 '19 at 01: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? – ElektrikSpark Jan 22 '19 at 01:04
  • 1
    You might be bundling from local system, which probably has `node` 11 installed. – Ganapati V S Jan 22 '19 at 01:05
  • Also possible duplicate of https://stackoverflow.com/questions/46384591/node-was-compiled-against-a-different-node-js-version-using-node-module-versio – Ganapati V S Jan 22 '19 at 01: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. – Ganapati V S Jan 22 '19 at 01:08
  • Alright, I will change my local node version to 8.10. Should work. – ElektrikSpark Jan 22 '19 at 01:11
  • Leaving it as answer just for reference. – Ganapati V S Jan 22 '19 at 01:24

3 Answers3

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.

Ganapati V S
  • 1,333
  • 10
  • 21
2

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
Gökhan Ayhan
  • 1,015
  • 11
  • 11
1

The following worked for me:

npm_config_arch=x64 npm_config_platform=linux npm install sharp

For some reason, arguments did not work.

haxpanel
  • 3,956
  • 3
  • 37
  • 66