Issue: FastAPI Deployment Fails with ModuleNotFoundError: No module named 'jose'
loveleetsaini
FREEOP

2 months ago

🧩 Issue: FastAPI Deployment Fails with ModuleNotFoundError: No module named 'jose'

πŸ“Œ Context

I’m deploying a FastAPI backend (Python 3.12) on Railway using a split architecture:

  • API service β†’ requirements.txt
  • Worker service β†’ requirements-worker.txt
  • Procfile:
web: uvicorn backend.main:app --host 0.0.0.0 --port $PORT  

The app works locally without issues, but fails after deployment.

🚨 Error Observed

From Railway logs:

ModuleNotFoundError: No module named 'jose'

πŸ‘‰

Stack trace shows failure during import:

from backend.app.core.jwt import create_access_token, decode_token
from jose import jwt, JWTError

πŸ“¦ Dependencies (Relevant Section)

requirements.txt includes:

fastapi==0.115.0
uvicorn[standard]==0.30.0
pydantic[email]==2.6.1

sqlalchemy==2.0.25
psycopg2-binary==2.9.9
asyncpg==0.29.0

python-jose[cryptography]==3.3.0  ← INCLUDED
passlib[bcrypt]==1.7.4
argon2-cffi==23.1.0

So the missing module should be installed.

πŸ” What I Already Verified

  • App imports successfully locally
  • python-jose[cryptography] is present in requirements.txt
  • No duplicate or conflicting dependency entries
  • No lazy import issues (JWT is required at startup)
  • Worker-related dependencies separated correctly
  • API does NOT import Celery / Redis at startup

πŸ§ͺ Observed Behavior

  • Railway deploy succeeds
  • Container starts
  • Immediately crashes on startup due to missing jose
  • Logs repeatedly show same import failure loop

πŸ€” Suspected Cause

This looks like a build cache issue, where:

  • Railway is not reinstalling dependencies
  • Cached layer is reused
  • python-jose never gets installed in runtime environment

❓ Questions

  1. Does Railway sometimes skip dependency installation due to caching, even when requirements.txt changes?
  2. What is the recommended way to force a clean rebuild?
  3. Is there a known issue with:
    • Python 3.12 + Nixpacks
    • Optional dependency syntax like python-jose[cryptography]?
  4. Should I:
    • Clear build cache manually?
    • Delete & recreate the service?
    • Use a custom build command?

🧯 Temporary Workarounds Tried

  • Added new lines to requirements.txt to force rebuild
  • Re-deployed multiple times
  • Verified Procfile and entrypoint

Still facing the same issue.

Expected Behavior

App should start successfully and expose:

/docs (Swagger UI)
/openapi.json

πŸ™ Help Needed

Looking for guidance on:

  • Forcing dependency reinstall on Railway
  • Diagnosing build cache issues
  • Any known compatibility issues with python-jose
Solved$10 Bounty

2 Replies

Status changed to Awaiting Railway Response Railway β€’ about 2 months ago


This is clearly an application-level issue (Python dependency/configuration problem) it's likely not the correct

requirements.txt

Status changed to Awaiting User Response Railway β€’ about 2 months ago


angelo-railway

This is clearly an application-level issue (Python dependency/configuration problem) it's likely not the correct ``` requirements.txt ```

loveleetsaini
FREEOP

2 months ago

requirements.txt

fastapi==0.115.0

uvicorn[standard]==0.30.0

pydantic[email]==2.6.1

python-dotenv==1.0.1

python-multipart==0.0.9

sqlalchemy==2.0.25

alembic==1.13.1

psycopg2-binary==2.9.9

asyncpg==0.29.0

databases==0.9.0

python-jose[cryptography]==3.3.0

passlib[bcrypt]==1.7.4

argon2-cffi==23.1.0

pandas==2.2.2

openpyxl==3.1.5

PyMuPDF==1.24.9

boto3==1.34.162

openai==1.40.6

tenacity==8.5.0

# force-rebuild-3


Status changed to Awaiting Railway Response Railway β€’ about 2 months ago


Status changed to Open Railway β€’ about 2 months ago


Status changed to Solved loveleetsaini β€’ about 2 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...