In a AWS Lambda/NodeJS runtime, I'm attempting to import from an absolute path (/opt/nodejs/node_modules/puppeteer).
Source runs fine locally but, once bundled with Webpack/serverless-webpack and run in AWS Lambda, require('puppeteer') results in:
{"errorMessage":"Cannot find module 'puppeteer'","errorType":"Error","stackTrace":["webpackMissingModule (/var/task/src/render/handler.js:643:89)","/var/task/src/render/handler.js:643:173","next (native)","step (/var/task/src/render/handler.js:608:191)","/var/task/src/render/handler.js:608:361"]}
I've checked:
- AWS Lambda Layer is mounted at
/opt. - The path
/opt/nodejs/node_modules/puppeteerdoes exist. NODE_PATHcorrectly includes/opt/nodejs/node_modules
Try running your script by forcing the environment variable $NODE_PATH. Such as:
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.