leonfancy / image-lambda

An AWS Lambda function that AWS S3 can invoke to create thumbnails or reduce file size for png and jpg images.
79 stars 11 forks source link

Cannot find module imagemin-pngquant #2

Open dariospadoni opened 7 years ago

dariospadoni commented 7 years ago

Hello I built the script with Vagrant, uploaded the zip file to S3 but I get this error when I test the function:


  "errorMessage": "Cannot find module 'imagemin-pngquant'",
  "errorType": "Error",
  "stackTrace": [
    "Object.<anonymous> (/var/task/lib/ImageProcessor.js:10:26)",
    "Module._compile (module.js:409:26)",
    "Object.Module._extensions..js (module.js:416:10)",
    "Module.load (module.js:343:32)",
    "Function.Module._load (module.js:300:12)",
    "Module.require (module.js:353:17)"
  ]
}```

I can see the imagemin-pngquant package inside the zip file...any idea?
leonfancy commented 7 years ago

Could you please send me your zip package? Your information is not enough to locate the issue.

dariospadoni commented 7 years ago

Sure: slim-lambda.zip

leonfancy commented 7 years ago

Your config.json file is wrong, you should write it as what documented in readme.

dariospadoni commented 7 years ago

Ah I see. So to semplify, I'm using now the following configuration

{
  "resizes": [
    {
      "width": 1200,
      "sourceDir": "./",
      "targetBucket": "amavido-dev",
      "targetDir": "optimized/hero",
      "ACL": "public-read"
    }
  ]
}

and I still get the same error. Are all the parameters required? For instance if I omit "sourceDir" and "targetBucket", is the function using the current bucket and folder of the uploaded image? (I also tried with "sourceDir": "" but same error again.

matthewberryman commented 7 years ago

@dariospadoni sorry I can't figure out why you're getting that error. However, I've now got a patch in that means you can omit the targetBucket (and if you do it will default to the same bucket as the original). I will look at doing a patch for omission of sourceDir. Note that you can't use the resize options {%}{@}{!}{<}{>}{^} yet, but I have a branch for that that I will submit as a pull request after I finish documenting it and merging the other pull request into my options branch if/when approved—I am not submitting patches all at once as otherwise it creates a bunch of merge conflicts (so I am saving the resolution work for myself).

dariospadoni commented 7 years ago

I ended up writing my own lambda function, it's here if anyone is interested