Cannot find module 'puppeteer'
You have to install your module with save
flag before uploading your zip to Amazon :
npm i puppeteer --save
npm i --save puppeteer
results in a too big package. (Max 50MB for Lambdas.)
So, instead, puppeteer was installed with npm i --save-dev puppeteer --ignore-scripts
. (Ignore scripts to prevent Chromium from being installed.) The serverless-webpack
plugin had to be told to ignore puppeteer in its packaging. (Otherwise puppeteer would bloat the package.)
The puppeteer module was put in a Layer (in the folder structure mentioned in the question) and require('puppeteer')
now works.
Try running your script by forcing the environment variable $NODE_PATH. Such as:
NODE_PATH=/opt/nodejs/node_modules /path/to/bin/node your-file.js
For a specific reason I had to build from source a version of node without affecting the currently installation and this workaround worked for me.
I've got to this solution based on the following question here.