Files
mwitnessing/_deploy/fix-npm-issues.sh
Dobromir Popov bf43efe75d scripts
2025-04-10 03:18:40 +03:00

72 lines
2.6 KiB
Bash

#!/bin/bash
# Script to fix npm installation issues in a running container
# Run this script inside the container if you encounter npm package problems
set -e
echo "====================================================="
echo "Running npm dependency fix script"
echo "====================================================="
# Navigate to app directory
cd /app
# Create logs directory if it doesn't exist
mkdir -p /app/logs
LOG_FILE="/app/logs/npm-fix.log"
echo "Starting npm fix at $(date)" > "$LOG_FILE"
# Check for Node.js version
NODE_VERSION=$(node -v)
echo "Node.js version: $NODE_VERSION" | tee -a "$LOG_FILE"
# Clean up node_modules
echo "Cleaning up node_modules..." | tee -a "$LOG_FILE"
# Remove specific problematic packages
echo "Removing problematic packages..." | tee -a "$LOG_FILE"
rm -rf node_modules/abbrev
rm -rf node_modules/bcrypt
rm -rf node_modules/node-pre-gyp
rm -rf node_modules/.bin/node-pre-gyp
# Clean npm cache
echo "Cleaning npm cache..." | tee -a "$LOG_FILE"
npm cache clean --force
# Install specific problematic packages individually
echo "Installing problematic packages individually..." | tee -a "$LOG_FILE"
echo "Installing abbrev..." | tee -a "$LOG_FILE"
npm install abbrev@latest --no-save --no-audit --no-fund || echo "Failed to install abbrev" | tee -a "$LOG_FILE"
echo "Installing bcrypt..." | tee -a "$LOG_FILE"
npm install bcrypt@latest --build-from-source --no-save --no-audit --no-fund || echo "Failed to install bcrypt" | tee -a "$LOG_FILE"
# Try reinstalling all dependencies
echo "Reinstalling all dependencies..." | tee -a "$LOG_FILE"
npm install --production --no-optional --legacy-peer-deps ||
npm install --production --no-optional --force ||
npm install --production --no-optional --no-package-lock ||
echo "WARNING: All npm install attempts failed" | tee -a "$LOG_FILE"
# Generate Prisma client
echo "Generating Prisma client..." | tee -a "$LOG_FILE"
npx prisma generate || echo "Failed to generate Prisma client" | tee -a "$LOG_FILE"
# Build Next.js application
echo "Building Next.js application..." | tee -a "$LOG_FILE"
npx next build || echo "Failed to build Next.js application" | tee -a "$LOG_FILE"
echo "====================================================="
echo "Fix script completed at $(date)" | tee -a "$LOG_FILE"
echo "Check $LOG_FILE for detailed output"
echo "====================================================="
echo "To restart the application, run:"
echo "1. Find the process ID: ps aux | grep 'npm start'"
echo "2. Kill the process: kill <PID>"
echo "3. Restart: npm start"
echo "Or use: pkill -f 'npm start' && npm start"
echo "====================================================="