Created
January 29, 2023 22:58
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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