Skip to content

🎥 Make videos programmatically with React

fix preview server crashing when public/ dir does not exist

Jonny Burger27c48796b25f
diff --git a/packages/cli/src/preview-server/public-folder.ts b/packages/cli/src/preview-server/public-folder.ts
index 6c4bd654b5..8f01c4e565 100644
--- a/packages/cli/src/preview-server/public-folder.ts
+++ b/packages/cli/src/preview-server/public-folder.ts
@@ -1,5 +1,5 @@
import {BundlerInternals} from '@remotion/bundler';
-import {watch} from 'fs';
+import {existsSync, watch} from 'fs';
import path from 'path';
// eslint-disable-next-line no-restricted-imports
import type {StaticFile} from 'remotion';
@@ -49,6 +49,23 @@ export const watchPublicFolder = ({
onUpdate: () => void;
staticHash: string;
}) => {
+ if (!existsSync(publicDir)) {
+ const parentDir = path.dirname(publicDir);
+ const onDirChange = () => {
+ if (existsSync(publicDir)) {
+ watchPublicFolder({
+ publicDir,
+ onUpdate,
+ staticHash,
+ });
+ watcher.close();
+ }
+ };
+
+ const watcher = watch(parentDir, {}, onDirChange);
+ return;
+ }
+
watch(publicDir, {recursive: true}, () => {
fetchFolder({publicDir, staticHash});
onUpdate();