Skip to content

Instantly share code, notes, and snippets.

@0x4007
Created January 29, 2023 22:58
Show Gist options
  • Save 0x4007/ab492dd086d0c813db3560d6d07a00ba to your computer and use it in GitHub Desktop.
Save 0x4007/ab492dd086d0c813db3560d6d07a00ba to your computer and use it in GitHub Desktop.
This helped me to setup puppeteer on my VPS. It kept throwing OS missing dependency errors, so this will parse the error and automatically install it.
const { execSync } = require('child_process');
function runYarn() {
// Run yarn ci command
try {
execSync('yarn ci');
console.log('yarn ci ran successfully');
} catch (err) {
// Extract the error message
const errorMessage = err.stderr.toString();
// Extract the missing library name from the error message
const rawName = errorMessage.match(/lib[^:]+\.so\.\d/)[0];
const libraryName = rawName.split(".so.").join("");
// Install the missing library using apt-get
try {
execSync(`sudo apt-get install -y ${libraryName}`);
console.log(`Successfully installed ${libraryName}`);
runYarn();
} catch (err) {
console.error(`Failed to install ${libraryName}. Error: ${err}`);
}
}
}
runYarn();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment