diff --git a/src/optimizeImages.ts b/src/optimizeImages.ts index aa1e1ff..64f51be 100755 --- a/src/optimizeImages.ts +++ b/src/optimizeImages.ts @@ -205,9 +205,11 @@ const nextImageExportOptimizer = async function () { ); // we clear all images in the remote image folder that are not in the remoteImageURLs array - const allFilesInRemoteImageFolder: string[] = fs.readdirSync( + const allFilesInRemoteImageFolder: string[] = fs.existsSync( folderNameForRemoteImages - ); + ) + ? fs.readdirSync(folderNameForRemoteImages) + : []; const encodedRemoteImageURLs = remoteImageURLs.map((url: string) => urlToFilename(url) );