chrome-aws-lambda: [BUG] Failed to launch the browser process: error while loading shared libraries: libnss3.so: cannot open shared object file
Environment
chrome-aws-lambda
Version: 3.0.4puppeteer
/puppeteer-core
Version: 3.0.4- OS: Mac
- Node.js Version: 12.x
- Lambda / GCF Runtime: nodejs12.x
Expected Behavior
Chrome should have load.
Current Behavior
Error: Failed to launch the browser process! /tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md at onClose (/var/task/node_modules/puppeteer-core/lib/Launcher.js:547:20) at Interface.<anonymous> (/var/task/node_modules/puppeteer-core/lib/Launcher.js:537:65) at Interface.emit (events.js:327:22) at Interface.EventEmitter.emit (domain.js:483:12) at Interface.close (readline.js:416:8) at Socket.onend (readline.js:194:10) at Socket.emit (events.js:327:22) at Socket.EventEmitter.emit (domain.js:483:12) at endReadableNT (_stream_readable.js:1220:12) at processTicksAndRejections (internal/process/task_queues.js:84:21)
Steps to Reproduce
const chromium = require('chrome-aws-lambda');
const puppeteer = require('puppeteer-core');
async convertToPdf(request) {
try {
console.log('Starting puppeteer browser.');
const browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: true,
ignoreHTTPSErrors: true
});
console.log('Puppeteer launched: ' + !!browser);
if (request.sections.length > 75) {
throw new Error('Only 75 report sections are allowed');
}
let pdfs = await Promise.all(_.map(request.sections, async (section, $index) => {
if (section.s3Pdf) {
let s3Response = await s3.getObject({
Bucket: section.s3Pdf.bucket,
Key: section.s3Pdf.key
}).promise();
console.log(`PDF ${$index} retrieved successfully`);
return s3Response.Body;
}
const page = await browser.newPage();
page.setViewport(request.viewPort || {
width: 1024,
height: 600
});
section.options = section.options || {};
console.log(`Loading section ${$index}...`);
await page.setContent(this.fromBase64(section.html), {waitUntil: ['networkidle0']});
console.log(`Section ${$index} Load complete. Converting html to pdf using puppeteer. Options: ${JSON.stringify(section.options)}`);
let body = await page.pdf(_.assign({format: 'letter'}, section.options));
console.log(`PDF ${$index} created successfully`);
page.close();
return body;
}));
Previously my code was running properly on nodejs8.10 supported AWS Lambda function but after forcefully upgrade to nodejs12.x, my code starts to throw this error. I tried upgrading chrome-aws-lambda and puppeteer-core version to 2.1.1 and even the latest 5.3.1 but no luck on resolving the issue.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 7
- Comments: 26 (2 by maintainers)
Here is how I fixed mine.
but replace the bracketed directories with the directories available in your node_modules folder. There you should find the local installation of chrome and from there you ran the next command.
on a Linux machine to check which dependencies are missing. Read more here Chrome headless doesn’t launch on UNIX
ldd chrome | grep not
this time nothing is shown on the terminal, so you should be good.That is it. You are good to go. Hopefully, this helps someone. 😄
I get the same error, but not related to AWS, but Linux on a Windows 10 machine using WSL 2 (Ubuntu 20.04.1 LTS) and Puppetter: 5.5.0:
ChromeHeadless stderr: /home/sandstedt/_open-source/mojs/node_modules/puppeteer/.local-chromium/linux-818858/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
Solved it by installing all missing dependencies listed here: Puppeteer Troubleshooting
@damisparks I have the same problem of running Puppeteer in AWS Lambda env. Lambda cannot run
sudo apt-get install
and not evenyum install
. In addition, all volumes except/tmp
are read-only so, the fix provided above is irrelevant. Is there any solution for this case?Anecdotally, I am seeing this only on the node16 runtime. When I use the node14 runtime it works fine, and when I bump to node16 I get the
error
I had this error and the fix was to set lambda memory to 512 mb.
I’m getting this same issue with:
This may be helpful to some, to check which libs are missing just do
cd /project_folder/node_modules/puppeteer/.local-chromium/linux-version/chrome-linux/ ldd chrome | grep not
make sure to change the folders to your own folders, hope this helps.I just pushed up my code to AWS Lambda, and I’m getting the exact same error. New deployment (actually never been deployed before), NodeJs12, using the shelfio layer.
Also got the same error following the instructions in the Lambda Layers option. The resulting zip file, pushed up to AWS Lambda, triggers the same error, missing libnss3.so .
I faced the same issue on AWS Lambda using Node 16.x. I did the following:
Hope this helps!
I didn’t noticed that my serverless.yml was on runtime: nodejs16.x. When I changed it to nodejs14.x I was able to run withou this error on aws lambda. Error: “/tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory” Fix: Changed serverless.yml to provider: name: aws runtime: nodejs14.x and redeployed
That layer is currently out of date. You can build your own up to date layer using my fork though
@skilbjo FWIW I was able to fix the issue by using the forked package by @Sparticuz in https://github.com/alixaxel/chrome-aws-lambda/pull/264
It’s not the exactly same case but I’ve seen same issue to initialize the browser object, missing libnss3.so. In my case it only happens when I run the lambda with aws-sam-cli in debug mode. Actually I don’t see the issue if I run the lambda at my local with normal mode (i.e. run with
sam local invoke
), but in debug mode (sam local invoke -d 5858
) I can see the error messageFailed to launch the browser process!\n/tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
.Actually I could notice that the environment variable
AWS_EXECUTION_ENV
is not defined in local lambda container if I run in debug mode, it’s there in normal mode on the other hand. And when I set that variable in template.yaml file (which contains the definition of serverless application in aws sam), then the error was gone. My experience is only in aws sam, but hope this can be a clue to resolve someone’s trouble. My environment is:Also, I know there are few lines which use
AWS_EXECUTION_ENV
as a switch to modify env variables like https://github.com/alixaxel/chrome-aws-lambda/blob/master/source/index.js#L6. It can be better to have more robust check routine since I’ve seen it’s not always defined.