From 78a51f88dc25bef13d34228b65bc8b9ebbb62f40 Mon Sep 17 00:00:00 2001 From: johnny2211 Date: Sun, 18 Jan 2026 18:57:37 +0100 Subject: [PATCH] Fix regenerate-all-gifs script for production environment Problem: Script failed in production Docker container because it tried to import from '../src/utils/gifGenerator.js' which doesn't exist in production (only compiled dist/ directory exists). Error: Cannot find module '/app/packages/backend/src/utils/gifGenerator.js' Solution: Use dynamic import with path detection to support both development and production environments. Changes: - Check if dist/utils/gifGenerator.js exists (production) - Fall back to src/utils/gifGenerator.js (development) - Use dynamic import with await to load the correct module This allows the script to work in both: - Development: npx tsx scripts/regenerate-all-gifs.ts - Production: Docker container with REGENERATE_GIFS=true Tested: Docker container now starts successfully and executes the GIF regeneration script without errors. Co-Authored-By: Auggie --- packages/backend/scripts/regenerate-all-gifs.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/backend/scripts/regenerate-all-gifs.ts b/packages/backend/scripts/regenerate-all-gifs.ts index a6029ff..2640c6c 100644 --- a/packages/backend/scripts/regenerate-all-gifs.ts +++ b/packages/backend/scripts/regenerate-all-gifs.ts @@ -1,5 +1,4 @@ import { PrismaClient, MediaKind } from '@prisma/client'; -import { generateGifFromVideo } from '../src/utils/gifGenerator.js'; import path from 'path'; import fs from 'fs'; import { fileURLToPath } from 'url'; @@ -7,6 +6,13 @@ import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); +// Dynamic import to support both dev (src/) and production (dist/) +const gifGeneratorPath = fs.existsSync(path.join(__dirname, '../dist/utils/gifGenerator.js')) + ? '../dist/utils/gifGenerator.js' + : '../src/utils/gifGenerator.js'; + +const { generateGifFromVideo } = await import(gifGeneratorPath); + const prisma = new PrismaClient(); async function regenerateAllGifs() {