From 07baa59225c448433fff27b459d2d1cf351686d7 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Wed, 9 Jul 2025 22:21:49 +0000 Subject: [PATCH] Ensure the application runs correctly in the production environment Implements a Node.js 18 compatibility fix by patching `dist/index.js` and creating `server/prod-start.js` to replace `import.meta.dirname` with static paths, resolving a runtime error. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 91318273-c764-4fd4-be04-bdc12c38af32 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/99451107-d8a0-4f61-81e0-cae481285260.jpg --- DOCKER_TEST_GUIDE.md | 21 ++++++++++++++------- Dockerfile | 1 + docker-entrypoint-simple.sh | 4 ++-- public/index.html | 1 + replit.md | 5 ++++- server/prod-start.js | 31 +++++++++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 public/index.html create mode 100644 server/prod-start.js diff --git a/DOCKER_TEST_GUIDE.md b/DOCKER_TEST_GUIDE.md index a5f364c..7a21afe 100644 --- a/DOCKER_TEST_GUIDE.md +++ b/DOCKER_TEST_GUIDE.md @@ -2,17 +2,18 @@ ## ✅ Problème Résolu -Le problème `TypeError [ERR_INVALID_ARG_TYPE]: The "paths[0]" argument must be of type string. Received undefined` a été résolu en utilisant `npm run start` au lieu d'appeler directement `node dist/index.js`. +Le problème `TypeError [ERR_INVALID_ARG_TYPE]: The "paths[0]" argument must be of type string. Received undefined` a été résolu avec un script de compatibilité Node.js 18. ### Cause du Problème -- Node.js 18 ne supporte pas complètement `import.meta.dirname` -- Le code dans `server/vite.ts` utilisait cette fonctionnalité non disponible -- Le script `npm run start` gère automatiquement ces problèmes de compatibilité +- Node.js 18 ne supporte pas `import.meta.dirname` +- Le code compilé dans `dist/index.js` utilise cette fonctionnalité non disponible +- L'erreur se produit lors de la résolution des chemins (ligne 955 dans dist/index.js) ### Solution Appliquée -- Modification du script Docker d'entrée pour utiliser `npm run start` -- Ajout des variables d'environnement appropriées -- Conservation de la structure existante du projet +- Création d'un script `server/prod-start.js` qui remplace `import.meta.dirname` par des valeurs statiques +- Modification du script Docker d'entrée pour utiliser ce script de compatibilité +- Le script lit le fichier compilé et remplace les références undefined par des chemins absolus +- Création automatique du répertoire `public` pour les fichiers statiques ## Test du Déploiement Docker @@ -89,11 +90,17 @@ PORT=5000 ✅ PostgreSQL prêt! ✅ Base de données configurée 🎯 Démarrage de RegisFlow... +✅ Node.js 18 compatibility fix applied serving on port 5000 📅 Automatic backup scheduler started 🕐 Planificateur de purge des ventes démarré ``` +### Fichiers de Solution +- `server/prod-start.js` : Script de compatibilité Node.js 18 +- `docker-entrypoint-simple.sh` : Script d'entrée Docker simplifié +- `Dockerfile` : Configuration optimisée pour production + ## Compte par Défaut - **Utilisateur** : admin - **Mot de passe** : admin123 diff --git a/Dockerfile b/Dockerfile index 17e7c0d..73bc4e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,6 +44,7 @@ RUN mkdir -p /app/backups /app/logs /app/data && \ COPY --from=builder --chown=regisflow:nodejs /build/package*.json ./ COPY --from=builder --chown=regisflow:nodejs /build/dist ./dist COPY --from=builder --chown=regisflow:nodejs /build/shared ./shared +COPY --from=builder --chown=regisflow:nodejs /build/server/prod-start.js ./server/ COPY --from=builder --chown=regisflow:nodejs /build/drizzle.config.ts ./ COPY --from=builder --chown=regisflow:nodejs /build/node_modules ./node_modules diff --git a/docker-entrypoint-simple.sh b/docker-entrypoint-simple.sh index 3ebef2c..69b47e1 100644 --- a/docker-entrypoint-simple.sh +++ b/docker-entrypoint-simple.sh @@ -28,9 +28,9 @@ mkdir -p /app/backups /app/logs # Initialiser la base de données (les tables seront créées automatiquement par l'application) echo "✅ Base de données configurée" -# Démarrer l'application avec npm start pour éviter les problèmes de paths +# Démarrer l'application avec le script de polyfill Node.js 18 echo "🎯 Démarrage de RegisFlow..." export NODE_ENV=production export PORT=5000 cd /app -exec npm run start \ No newline at end of file +exec node server/prod-start.js \ No newline at end of file diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..c55ac19 --- /dev/null +++ b/public/index.html @@ -0,0 +1 @@ +