Static files not found when deploying Django project on Heroku - reactjs

I'm writing a project with a TypeScript/React frontend built using Webpack and a backend run by Django. Running npm run build and then ./manage.py collectstatic works fine locally. But I'm running into problems trying to deploy my project on Heroku. I know this question's been asked plenty of times, but none of the other solutions have worked for me.
Here's what I get when I run git push heroku main:
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 4 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (10/10), 1.26 KiB | 644.00 KiB/s, done.
Total 10 (delta 7), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpacks:
remote: 1. heroku/nodejs
remote: 2. heroku/python
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 14.x...
remote: Downloading and installing node 14.17.1...
remote: Using default npm version: 6.14.13
remote:
remote: -----> Restoring cache
remote: - node_modules
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote: added 5 packages in 0.409s
remote:
remote: -----> Build
remote:
remote: -----> Caching build
remote: - node_modules
remote:
remote: -----> Pruning devDependencies
remote: audited 5 packages in 0.353s
remote: found 0 vulnerabilities
remote:
remote:
remote: -----> Build succeeded!
remote: -----> Python app detected
remote: -----> Using Python version specified in Pipfile.lock
remote: cp: cannot stat '/tmp/build_a2c93ee9/requirements.txt': No such file or directory
remote: -----> Using cached install of python-3.9.6
remote: -----> Installing pip 20.2.4, setuptools 47.1.1 and wheel 0.36.2
remote: Skipping installation, as Pipfile.lock hasn't changed since last deploy.
remote: -----> Installing SQLite3
remote: -----> $ python manage.py collectstatic --noinput
remote: 152 static files copied to '/tmp/build_a2c93ee9/staticfiles', 476 post-processed.
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 111.1M
remote: -----> Launching...
remote: Released v14
remote: https://myproject.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/myproject.git
+ 60592b5...2777b0e main -> main (forced update)
settings.py (this is the only settings file in the project):
import django_heroku
import dj_database_url
import os
import subprocess
import whitenoise
from datetime import timedelta
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = os.environ.get('SECRET_KEY')
ALLOWED_HOSTS = [ 'localhost' ]
CORS_ORIGIN_WHITELIST = [
'http://localhost:3000',
'http://localhost:8000',
'http://localhost:8080',
'http://localhost:5432',
]
CORS_ALLOW_HEADERS = (
'x-requested-with',
'content-type',
'accept',
'origin',
'authorization',
'x-csrftoken'
)
REACT_APP_API_ENDPOINT = 'http://localhost:8000/'
DEBUG = True
if os.environ.get('NODE_ENV'):
DEBUG = False
REACT_APP_API_ENDPOINT = 'http://myproject.com/'
ALLOWED_HOSTS = [ '.herokuapp.com', 'myproject.com' ]
CORS_ORIGIN_WHITELIST = [
'http://myproject.com/',
'http://myproject.herokuapp.com/',
'http://*.herokuapp.com/',
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'authentication',
'corsheaders',
'rest_framework',
'notebooks',
'frontend',
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'core.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'core.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('DATABASE_NAME'),
'USER': os.environ.get('DB_OWNER_USERNAME'),
'PASSWORD': os.environ.get('DB_OWNER_PASSWORD'),
'HOST': os.environ.get('DATABASE_URL'),
'PORT': os.environ.get('DB_PORT'),
}
}
if os.environ.get('NODE_ENV'):
credentials = subprocess.check_output([
'/bin/bash',
'-c',
'heroku config:get DATABASE_URL -a myproject',
], shell=True).decode('utf-8')
DATABASES['default'] = dj_database_url.config(default=credentials, conn_max_age=600)
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'frontend', 'static', 'frontend'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
# Miscellaneous
MAX_SLUG_LENGTH = 15
APPEND_SLASH = True
AUTH_USER_MODEL = 'authentication.MyProjectUser'
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
)
}
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(hours=24),
'REFRESH_TOKEN_LIFETIME': timedelta(days=30),
'ROTATE_REFRESH_TOKENS': True,
'BLACKLIST_AFTER_ROTATION': False,
'ALGORITHM': 'HS256',
'SIGNING_KEY': SECRET_KEY,
'VERIFYING_KEY': None,
'AUTH_HEADER_TYPES': ('JWT',),
'USER_ID_FIELD': 'email',
'USER_ID_CLAIM': 'login_email',
'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
'TOKEN_TYPE_CLAIM': 'token_type',
}
# Logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': ('%(asctime)s [%(process)d] [%(levelname)s] '
'pathname=%(pathname)s lineno=%(lineno)s '
'funcname=%(funcName)s %(message)s'),
'datefmt': '%Y-%m-%d %H:%M:%S'
},
'simple': {
'format': '%(levelname)s %(message)s'
}
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
'django.request': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
}
}
django_heroku.settings(locals(), logging=False, databases=False)
Error message:
2021-06-30T16:23:00.826686+00:00 app[web.1]: raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
2021-06-30T16:23:00.826687+00:00 app[web.1]: ValueError: Missing staticfiles manifest entry for 'frontend/favicon.ico'
2021-06-30T16:23:00.827738+00:00 heroku[router]: at=info method=GET path="/" host=myproject.herokuapp.com request_id=503bf0f8-f9a7-4fba-b8e8-5829d66536ba fwd="37.120.244.101" dyno=web.1 connect=2ms service=495ms status=500 bytes=227 protocol=https
2021-06-30T16:23:00.827751+00:00 app[web.1]: 10.136.167.231 - - [30/Jun/2021:16:23:00 +0000] "GET / HTTP/1.1" 500 27 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
Logs with full traceback:
2021-06-30T16:05:14.449877+00:00 app[web.1]: response = get_response(request)
2021-06-30T16:05:14.449879+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/core/handlers/base.py", line 115, in _get_response
2021-06-30T16:05:14.449880+00:00 app[web.1]: response = self.process_exception_by_middleware(e, request)
2021-06-30T16:05:14.449881+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/core/handlers/base.py", line 113, in _get_response
2021-06-30T16:05:14.449881+00:00 app[web.1]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
2021-06-30T16:05:14.449882+00:00 app[web.1]: File "/app/frontend/views.py", line 4, in index
2021-06-30T16:05:14.449882+00:00 app[web.1]: return render(request, 'index.html')
2021-06-30T16:05:14.449882+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/shortcuts.py", line 36, in render
2021-06-30T16:05:14.449883+00:00 app[web.1]: content = loader.render_to_string(template_name, context, request, using=using)
2021-06-30T16:05:14.449884+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/loader.py", line 62, in render_to_string
2021-06-30T16:05:14.449884+00:00 app[web.1]: return template.render(context, request)
2021-06-30T16:05:14.449884+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
2021-06-30T16:05:14.449885+00:00 app[web.1]: return self.template.render(context)
2021-06-30T16:05:14.449885+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 171, in render
2021-06-30T16:05:14.449886+00:00 app[web.1]: return self._render(context)
2021-06-30T16:05:14.449886+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 163, in _render
2021-06-30T16:05:14.449886+00:00 app[web.1]: return self.nodelist.render(context)
2021-06-30T16:05:14.449887+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 937, in render
2021-06-30T16:05:14.449887+00:00 app[web.1]: bit = node.render_annotated(context)
2021-06-30T16:05:14.449887+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 904, in render_annotated
2021-06-30T16:05:14.449888+00:00 app[web.1]: return self.render(context)
2021-06-30T16:05:14.449888+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/templatetags/static.py", line 106, in render
2021-06-30T16:05:14.449889+00:00 app[web.1]: url = self.url(context)
2021-06-30T16:05:14.449889+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/templatetags/static.py", line 103, in url
2021-06-30T16:05:14.449889+00:00 app[web.1]: return self.handle_simple(path)
2021-06-30T16:05:14.449890+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/templatetags/static.py", line 118, in handle_simple
2021-06-30T16:05:14.449890+00:00 app[web.1]: return staticfiles_storage.url(path)
2021-06-30T16:05:14.449890+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 153, in url
2021-06-30T16:05:14.449891+00:00 app[web.1]: return self._url(self.stored_name, name, force)
2021-06-30T16:05:14.449891+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 132, in _url
2021-06-30T16:05:14.449892+00:00 app[web.1]: hashed_name = hashed_name_func(*args)
2021-06-30T16:05:14.449892+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 420, in stored_name
2021-06-30T16:05:14.449892+00:00 app[web.1]: raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
2021-06-30T16:05:14.449893+00:00 app[web.1]: ValueError: Missing staticfiles manifest entry for 'frontend/favicon.ico'
2021-06-30T16:05:14.454870+00:00 app[web.1]: 10.181.54.2 - - [30/Jun/2021:16:05:14 +0000] "GET / HTTP/1.1" 500 27 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
2021-06-30T16:05:14.455485+00:00 heroku[router]: at=info method=GET path="/" host=myproject.herokuapp.com request_id=ee6c5f47-b78a-4201-9d14-65730c6e5f91 fwd="37.120.244.101" dyno=web.1 connect=0ms service=10921ms status=500 bytes=227 protocol=https
2021-06-30T16:16:23.000000+00:00 app[api]: Build started by user jpaulvalen#gmail.com
2021-06-30T16:16:47.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/dc89d2bf-8113-4bc6-a61d-89c7c127893f/activity/builds/2002371a-a4af-46cc-94f0-31425feb0ea5
2021-06-30T16:21:33.000000+00:00 app[api]: Build started by user jpaulvalen#gmail.com
2021-06-30T16:22:22.483318+00:00 app[api]: Release v14 created by user jpaulvalen#gmail.com
2021-06-30T16:22:22.483318+00:00 app[api]: Deploy 2777b0e3 by user jpaulvalen#gmail.com
2021-06-30T16:22:23.366584+00:00 heroku[web.1]: Restarting
2021-06-30T16:22:23.388293+00:00 heroku[web.1]: State changed from up to starting
2021-06-30T16:22:24.657187+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-06-30T16:22:24.835654+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [31] [INFO] Worker exiting (pid: 31)
2021-06-30T16:22:24.835669+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [32] [INFO] Worker exiting (pid: 32)
2021-06-30T16:22:24.836132+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [4] [WARNING] Worker with pid 27 was terminated due to signal 15
2021-06-30T16:22:24.836510+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [4] [INFO] Handling signal: term
2021-06-30T16:22:24.842055+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [4] [WARNING] Worker with pid 31 was terminated due to signal 15
2021-06-30T16:22:24.845543+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [4] [WARNING] Worker with pid 32 was terminated due to signal 15
2021-06-30T16:22:24.937231+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [4] [INFO] Shutting down: Master
2021-06-30T16:22:25.730105+00:00 heroku[web.1]: Process exited with status 0
2021-06-30T16:22:36.000000+00:00 app[api]: Build succeeded
2021-06-30T16:22:37.995504+00:00 heroku[web.1]: Starting process with command `gunicorn core.wsgi`
2021-06-30T16:22:43.648378+00:00 app[web.1]: [heroku-exec] Starting
2021-06-30T16:22:44.744285+00:00 app[web.1]: [2021-06-30 16:22:44 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-06-30T16:22:44.744326+00:00 app[web.1]: [2021-06-30 16:22:44 +0000] [4] [INFO] Listening at: http://0.0.0.0:55456 (4)
2021-06-30T16:22:44.744326+00:00 app[web.1]: [2021-06-30 16:22:44 +0000] [4] [INFO] Using worker: sync
2021-06-30T16:22:44.752288+00:00 app[web.1]: [2021-06-30 16:22:44 +0000] [36] [INFO] Booting worker with pid: 36
2021-06-30T16:22:44.784288+00:00 app[web.1]: [2021-06-30 16:22:44 +0000] [38] [INFO] Booting worker with pid: 38
2021-06-30T16:22:45.285535+00:00 heroku[web.1]: State changed from starting to up
2021-06-30T16:23:00.826647+00:00 app[web.1]: 2021-06-30 16:23:00 [36] [ERROR] pathname=/app/.heroku/python/lib/python3.9/site-packages/django/utils/log.py lineno=222 funcname=log_response Internal Server Error: /
2021-06-30T16:23:00.826669+00:00 app[web.1]: Traceback (most recent call last):
2021-06-30T16:23:00.826670+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/core/handlers/exception.py", line 34, in inner
2021-06-30T16:23:00.826671+00:00 app[web.1]: response = get_response(request)
2021-06-30T16:23:00.826672+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/core/handlers/base.py", line 115, in _get_response
2021-06-30T16:23:00.826673+00:00 app[web.1]: response = self.process_exception_by_middleware(e, request)
2021-06-30T16:23:00.826674+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/core/handlers/base.py", line 113, in _get_response
2021-06-30T16:23:00.826674+00:00 app[web.1]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
2021-06-30T16:23:00.826675+00:00 app[web.1]: File "/app/frontend/views.py", line 4, in index
2021-06-30T16:23:00.826675+00:00 app[web.1]: return render(request, 'index.html')
2021-06-30T16:23:00.826676+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/shortcuts.py", line 36, in render
2021-06-30T16:23:00.826677+00:00 app[web.1]: content = loader.render_to_string(template_name, context, request, using=using)
2021-06-30T16:23:00.826677+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/loader.py", line 62, in render_to_string
2021-06-30T16:23:00.826677+00:00 app[web.1]: return template.render(context, request)
2021-06-30T16:23:00.826678+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
2021-06-30T16:23:00.826678+00:00 app[web.1]: return self.template.render(context)
2021-06-30T16:23:00.826679+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 171, in render
2021-06-30T16:23:00.826679+00:00 app[web.1]: return self._render(context)
2021-06-30T16:23:00.826679+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 163, in _render
2021-06-30T16:23:00.826680+00:00 app[web.1]: return self.nodelist.render(context)
2021-06-30T16:23:00.826680+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 937, in render
2021-06-30T16:23:00.826680+00:00 app[web.1]: bit = node.render_annotated(context)
2021-06-30T16:23:00.826681+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 904, in render_annotated
2021-06-30T16:23:00.826681+00:00 app[web.1]: return self.render(context)
2021-06-30T16:23:00.826682+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/templatetags/static.py", line 106, in render
2021-06-30T16:23:00.826682+00:00 app[web.1]: url = self.url(context)
2021-06-30T16:23:00.826683+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/templatetags/static.py", line 103, in url
2021-06-30T16:23:00.826683+00:00 app[web.1]: return self.handle_simple(path)
2021-06-30T16:23:00.826683+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/templatetags/static.py", line 118, in handle_simple
2021-06-30T16:23:00.826684+00:00 app[web.1]: return staticfiles_storage.url(path)
2021-06-30T16:23:00.826684+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 153, in url
2021-06-30T16:23:00.826685+00:00 app[web.1]: return self._url(self.stored_name, name, force)
2021-06-30T16:23:00.826685+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 132, in _url
2021-06-30T16:23:00.826685+00:00 app[web.1]: hashed_name = hashed_name_func(*args)
2021-06-30T16:23:00.826686+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 420, in stored_name
2021-06-30T16:23:00.826686+00:00 app[web.1]: raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
2021-06-30T16:23:00.826687+00:00 app[web.1]: ValueError: Missing staticfiles manifest entry for 'frontend/favicon.ico'
2021-06-30T16:23:00.827738+00:00 heroku[router]: at=info method=GET path="/" host=myproject.herokuapp.com request_id=503bf0f8-f9a7-4fba-b8e8-5829d66536ba fwd="37.120.244.101" dyno=web.1 connect=2ms service=495ms status=500 bytes=227 protocol=https
2021-06-30T16:23:00.827751+00:00 app[web.1]: 10.136.167.231 - - [30/Jun/2021:16:23:00 +0000] "GET / HTTP/1.1" 500 27 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
EDIT:
Here's what I get when I take off whitenoise and set django_heroku's staticfiles setting to False:
2021-06-30T16:35:15.953366+00:00 heroku[web.1]: State changed from starting to up
2021-06-30T16:35:25.051217+00:00 app[web.1]: 10.157.141.243 - - [30/Jun/2021:16:35:25 +0000] "GET / HTTP/1.1" 200 424 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
2021-06-30T16:35:25.051447+00:00 heroku[router]: at=info method=GET path="/" host=myproject.herokuapp.com request_id=f96afeff-7704-431c-afa6-aa364df09df9 fwd="37.120.244.101" dyno=web.1 connect=1ms service=497ms status=200 bytes=621 protocol=https
2021-06-30T16:35:25.267943+00:00 app[web.1]: 2021-06-30 16:35:25 [34] [WARNING] pathname=/app/.heroku/python/lib/python3.9/site-packages/django/utils/log.py lineno=222 funcname=log_response Not Found: /static/frontend/index.js
2021-06-30T16:35:25.268873+00:00 app[web.1]: 10.157.141.243 - - [30/Jun/2021:16:35:25 +0000] "GET /static/frontend/index.js HTTP/1.1" 404 77 "https://myproject.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
2021-06-30T16:35:25.269357+00:00 heroku[router]: at=info method=GET path="/static/frontend/index.js" host=myproject.herokuapp.com request_id=306c0e1f-d1c5-4ebf-b15b-4f03f69ba424 fwd="37.120.244.101" dyno=web.1 connect=2ms service=134ms status=404 bytes=265 protocol=https
Maybe Heroku isn't building my frontend properly, and so collectstatic never finds it?

It is done, just type in heroku open and if it is showing application error type heroku run python manage.py migrate

Related

Heroku app successfully deploying, but received application error when loading site

Application error
An error occurred in the application and your page
could not be served. If you are the application owner, check your logs
for details. You can do this from the Heroku CLI with the command
heroku logs --tail
How can i resolve this?
Heroku logs
2010-09-16T15:13:46.677020+00:00 app[web.1]: Processing PostController#list (for 208.39.138.12 at 2010-09-16 15:13:46) [GET]
2010-09-16T15:13:46.677023+00:00 app[web.1]: Rendering template within layouts/application
2010-09-16T15:13:46.677902+00:00 app[web.1]: Rendering post/list
2010-09-16T15:13:46.678990+00:00 app[web.1]: Rendered includes/_header (0.1ms)
2010-09-16T15:13:46.698234+00:00 app[web.1]: Completed in 74ms (View: 31, DB: 40) | 200 OK [http://myapp.heroku.com/]
2010-09-16T15:13:46.723498+00:00 heroku[router]: at=info method=GET path="/posts" host=myapp.herokuapp.com" fwd="204.204.204.204" dyno=web.1 connect=1ms service=18ms status=200 bytes=975
2010-09-16T15:13:47.893472+00:00 app[worker.1]: 2 jobs processed at 16.6761 j/s, 0 failed ...

Single page web app connectionString error

i have successfully deployed multilayered app to heroku.
Now i am trying to do the same with single layer web app and its acting weird.
It is working on my local machine with no issues. But when i deploy it on heroku (i did the db migration and logged into heroku db to make sure.)
And now when i run app i get
System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString'). I cant figure out why its throwing that error, i didnt changed anything.
2022-06-01T16:46:05.058614+00:00 heroku[router]: at=info method=GET path="/" host=kriptodonacija.herokuapp.com request_id=30d7bf9f-eda8-43c1-baaf-10ce5792aa44 fwd="94.189.137.130" dyno=web.1 connect=0ms service=3ms status=500 bytes=130 protocol=https
2022-06-01T16:46:05.057150+00:00 app[web.1]: [16:46:05 INF] Request starting HTTP/1.1 GET http://kriptodonacija.herokuapp.com/ - -
2022-06-01T16:46:05.060435+00:00 app[web.1]: [16:46:05 ERR] Connection id "0HMI3T8NBRKQO", Request id "0HMI3T8NBRKQO:00000002": An unhandled exception was thrown by the application.
2022-06-01T16:46:05.060447+00:00 app[web.1]: Autofac.Core.DependencyResolutionException: An exception was thrown while activating Volo.Abp.SettingManagement.EntityFrameworkCore.SettingManagementDbContext -> λ:Microsoft.EntityFrameworkCore.DbContextOptions`1[[Volo.Abp.SettingManagement.EntityFrameworkCore.SettingManagementDbContext, Volo.Abp.SettingManagement.EntityFrameworkCore, Version=5.2.2.0, Culture=neutral, PublicKeyToken=null]].
2022-06-01T16:46:05.060448+00:00 app[web.1]: ---> System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString')
2022-06-01T16:46:05.060449+00:00 app[web.1]: at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
2022-06-01T16:46:05.060450+00:00 app[web.1]: at Microsoft.EntityFrameworkCore.NpgsqlDbContextOptionsBuilderExtensions.UseNpgsql(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 npgsqlOptionsAction)
2022-06-01T16:46:05.060451+00:00 app[web.1]: at Volo.Abp.EntityFrameworkCore.AbpDbContextConfigurationContextPostgreSqlExtensions.UseNpgsql(AbpDbContextConfigurationContext context, Action`1 postgreSqlOptionsAction)
2022-06-01T16:46:05.060451+00:00 app[web.1]: at CryptoDonor.CryptoDonorModule.<>c.<ConfigureEfCore>b__14_2(AbpDbContextConfigurationContext configurationContext) in /tmp/build_1a1be254/CryptoDonor/CryptoDonorModule.cs:line 290
2022-06-01T16:46:05.060452+00:00 app[web.1]: at Volo.Abp.EntityFrameworkCore.DependencyInjection.DbContextOptionsFactory.Configure[TDbContext](AbpDbContextOptions options, AbpDbContextConfigurationContext`1 context)
2022-06-01T16:46:05.060452+00:00 app[web.1]: at Volo.Abp.EntityFrameworkCore.DependencyInjection.DbContextOptionsFactory.Create[TDbContext](IServiceProvider serviceProvider)
2022-06-01T16:46:05.060453+00:00 app[web.1]: at Autofac.Extensions.DependencyInjection.AutofacRegistration.<>c__DisplayClass3_0.<Register>b__0(IComponentContext context, IEnumerable`1 parameters)
2022-06-01T16:46:05.060454+00:00 app[web.1]: at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
2022-06-01T16:46:05.060454+00:00 app[web.1]: at Autofac.Core.Activators.Delegate.DelegateActivator.<ConfigurePipeline>b__2_0(ResolveRequestContext ctxt, Action`1 next)
2022-06-01T16:46:05.060457+00:00 app[web.1]: at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
2022-06-01T16:46:05.060457+00:00 app[web.1]: at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
2022-06-01T16:46:05.060458+00:00 app[web.1]: --- End of inner exception stack trace ---
2022-06-01T16:46:05.060459+00:00 app[web.1]: at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
2022-06-01T16:46:05.060459+00:00 app[web.1]: at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
2022-06-01T16:46:05.060460+00:00 app[web.1]: at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 next)
2022-06-01T16:46:05.060460+00:00 app[web.1]: at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request)
2022-06-01T16:46:05.060460+00:00 app[web.1]: at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request)
2022-06-01T16:46:05.060461+00:00 app[web.1]: at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
2022-06-01T16:46:05.060461+00:00 app[web.1]: at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
2022-06-01T16:46:05.060462+00:00 app[web.1]: at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
2022-06-01T16:46:05.060462+00:00 app[web.1]: at Volo.Abp.Uow.EntityFrameworkCore.UnitOfWorkDbContextProvider`1.CreateDbContextAsync(IUnitOfWork unitOfWork)
2022-06-01T16:46:05.060462+00:00 app[web.1]: at Volo.Abp.Uow.EntityFrameworkCore.UnitOfWorkDbContextProvider`1.CreateDbContextAsync(IUnitOfWork unitOfWork, String connectionStringName, String connectionString)
2022-06-01T16:46:05.060463+00:00 app[web.1]: at Volo.Abp.Uow.EntityFrameworkCore.UnitOfWorkDbContextProvider`1.GetDbContextAsync()
2022-06-01T16:46:05.060463+00:00 app[web.1]: at Volo.Abp.Domain.Repositories.EntityFrameworkCore.EfCoreRepository`2.GetDbSetAsync()
2022-06-01T16:46:05.060465+00:00 app[web.1]: at Volo.Abp.SettingManagement.EntityFrameworkCore.EfCoreSettingRepository.GetListAsync(String providerName, String providerKey, CancellationToken cancellationToken)
2022-06-01T16:46:05.060466+00:00 app[web.1]: at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
2022-06-01T16:46:05.060466+00:00 app[web.1]: at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
2022-06-01T16:46:05.060467+00:00 app[web.1]: at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
2022-06-01T16:46:05.060467+00:00 app[web.1]: at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
2022-06-01T16:46:05.060467+00:00 app[web.1]: at Volo.Abp.SettingManagement.SettingManagementStore.SetCacheItemsAsync(String providerName, String providerKey, String currentName, SettingCacheItem currentCacheItem)
2022-06-01T16:46:05.060470+00:00 app[web.1]: at Volo.Abp.SettingManagement.SettingManagementStore.GetCacheItemAsync(String name, String providerName, String providerKey)
2022-06-01T16:46:05.060470+00:00 app[web.1]: at Volo.Abp.SettingManagement.SettingManagementStore.GetOrNullAsync(String name, String providerName, String providerKey)
2022-06-01T16:46:05.060471+00:00 app[web.1]: at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
2022-06-01T16:46:05.060471+00:00 app[web.1]: at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
2022-06-01T16:46:05.060471+00:00 app[web.1]: at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
2022-06-01T16:46:05.060474+00:00 app[web.1]: at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
2022-06-01T16:46:05.060475+00:00 app[web.1]: at Volo.Abp.Settings.TenantSettingValueProvider.GetOrNullAsync(SettingDefinition setting)
2022-06-01T16:46:05.060476+00:00 app[web.1]: at Volo.Abp.Settings.SettingProvider.GetOrNullValueFromProvidersAsync(IEnumerable`1 providers, SettingDefinition setting)
2022-06-01T16:46:05.060477+00:00 app[web.1]: at Volo.Abp.Settings.SettingProvider.GetOrNullAsync(String name)
2022-06-01T16:46:05.060480+00:00 app[web.1]: at Microsoft.AspNetCore.RequestLocalization.DefaultAbpRequestLocalizationOptionsProvider.GetLocalizationOptionsAsync()
2022-06-01T16:46:05.060480+00:00 app[web.1]: at Microsoft.AspNetCore.RequestLocalization.AbpRequestLocalizationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
2022-06-01T16:46:05.060482+00:00 app[web.1]: at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
2022-06-01T16:46:05.060483+00:00 app[web.1]: --- End of stack trace from previous location ---
any suggestions?
When i was creating git, .gitignore file had appsettings in it. So i didnt push config to heroku. after including it all works well.

Error: Unable to load application: NameError: undefined local variable or method `controller_path' for Object:Class - When pushing to Heroku

beginner here learning how to push a project to production. I am pushing my ReactJS app that has a server side and client side to Heroku and have the following error code that leads to it crashing on Heroku:
2022-05-06T14:51:18.301196+00:00 heroku[web.1]: State changed from crashed to starting
2022-05-06T14:51:26.595277+00:00 heroku[web.1]: Starting process with command `bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}`
2022-05-06T14:51:27.963617+00:00 app[web.1]: Puma starting in single mode...
2022-05-06T14:51:27.963633+00:00 app[web.1]: * Puma version: 5.6.2 (ruby 3.1.1-p18) ("Birdie's Version")
2022-05-06T14:51:27.963634+00:00 app[web.1]: * Min threads: 5
2022-05-06T14:51:27.963634+00:00 app[web.1]: * Max threads: 5
2022-05-06T14:51:27.963635+00:00 app[web.1]: * Environment: production
2022-05-06T14:51:27.963637+00:00 app[web.1]: * PID: 4
2022-05-06T14:51:30.556016+00:00 app[web.1]: ! Unable to load application: NameError: undefined local variable or method `controller_path' for Object:Class
2022-05-06T14:51:30.556031+00:00 app[web.1]:
2022-05-06T14:51:30.556032+00:00 app[web.1]: controller_path
2022-05-06T14:51:30.556033+00:00 app[web.1]: ^^^^^^^^^^^^^^^
2022-05-06T14:51:30.556170+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/3.1.0/bin/puma)
I have added in authentication with this app using the Devise token and have added in a static controller to my routes:
require 'rails/application_controller'
class StaticController < Rails::ApplicationController
layout false
def index
render file: Rails.root.join('public', 'index.html')
end
end
Here is my routes:
Rails.application.routes.draw do
mount_devise_token_auth_for 'User', at: 'api/auth'
namespace :api do
resources :users, only: :update
resources :workouts
end
get '*other', to: 'static#index'
end
Any ideas why this error code is showing up and how I can fix it?
Thanks

Static files not found when Docker container is running in Django React app

I am trying to run my Docker image to see it on my browser yet all that appears is an empty screen, upon inspection I see the following errors:
[2020-09-12 17:31:42 +0000] [12] [INFO] Starting gunicorn 20.0.4
[2020-09-12 17:31:42 +0000] [12] [INFO] Listening at: http://0.0.0.0:8000 (12)
[2020-09-12 17:31:42 +0000] [12] [INFO] Using worker: sync
[2020-09-12 17:31:42 +0000] [14] [INFO] Booting worker with pid: 14
Not Found: /static/js/2.8ba00362.chunk.js
Not Found: /static/js/main.8eee128b.chunk.js
Not Found: /static/css/2.7253a256.chunk.css
Not Found: /static/css/main.a85cbe2c.chunk.css
The commands I have run are:
docker build . -t projecthub and docker run -d -p 8000:8000 --name theprojecthub projecthub:latest
I am very unsure why these static files are even being looked for, I cannot seem to find any reference to them in my code. Does anybody know what I should do?
Here is my Dockerfile:
FROM myfriendsaccount/django-npm:latest
RUN mkdir usr/src/app
WORKDIR /usr/src/app
COPY frontend ./frontend
COPY backend ./backend
WORKDIR /usr/src/app/frontend
RUN npm install
RUN npm run build
WORKDIR /usr/src/app/backend
ENV DJANGO_PRODUCTION=True
RUN pip3 install -r requirements.txt
EXPOSE 8000
CMD python3 manage.py collectstatic && \
python3 manage.py makemigrations && \
python3 manage.py migrate && \
gunicorn project_hub.wsgi --bind 0.0.0.0:$PORT
Here are the relevant parts of my settings.py file:
DEBUG = True
if DEBUG:
APP_URL = "http://localhost:8000/"
else:
APP_URL = "https://" + PRODUCTION_URL + "/"
PRODUCTION_URL = 'mywebsite.com'
ALLOWED_HOSTS = ['http://localhost:3000', 'localhost', 'http://localhost:8000', '127.0.0.1', '[::1]', PRODUCTION_URL, '0.0.0.0']
...
CORS_ORIGIN_WHITELIST = [
'http://localhost:3000', 'http://localhost:8000',
]
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, '../frontend/build/static'),
]
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
This is what is inside my frontend/build/static:

Heroku - Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch using Webpack

been using the http://jumbo-react.g-axon.com/ framework for a client. This framework is based on react and uses webpack to build. It works on my local machine, but when uploading to Heroku I get this error:
react-material#2.0.0 start /app
2018-08-24T10:05:46.551774+00:00 app[web.1]: > webpack-dev-server --hot --open
2018-08-24T10:05:46.551775+00:00 app[web.1]:
2018-08-24T10:05:47.905809+00:00 app[web.1]: Project is running at http://localhost:24282/
2018-08-24T10:05:47.906248+00:00 app[web.1]: webpack output is served from /assets/
2018-08-24T10:05:47.906347+00:00 app[web.1]: Content not from webpack is served from ./public/, ./src/
2018-08-24T10:05:47.906399+00:00 app[web.1]: 404s will fallback to /index.html
2018-08-24T10:05:47.939064+00:00 app[web.1]: Unable to open browser. If you are running in a headless environment, please do not use the open flag.
2018-08-24T10:06:37.917006+00:00 app[web.1]: Hash: 7feed7b626257881787d
2018-08-24T10:06:37.917049+00:00 app[web.1]: Version: webpack 3.12.0
2018-08-24T10:06:37.917052+00:00 app[web.1]: Time: 49556ms
2018-08-24T10:06:37.917058+00:00 app[web.1]: Asset Size Chunks
2018-08-24T10:06:37.917128+00:00 app[web.1]:
Cut the middle to make it easier to read
2018-08-24T10:06:37.917146+00:00 app[web.1]: [../node_modules/webpack/hot/log.js] (webpack)/hot/log.js 1.04 kB {30} [built]
2018-08-24T10:06:37.917124+00:00 app[web.1]: [../node_modules/react-hot-loader/patch.js] ./node_modules/react-hot-loader/patch.js 40 bytes {30} [built]
2018-08-24T10:06:37.917147+00:00 app[web.1]: [../node_modules/webpack/hot/only-dev-server.js] (webpack)/hot/only-dev-server.js 2.37 kB {30} [built]
2018-08-24T10:06:37.917143+00:00 app[web.1]: [../node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js 77 bytes {30} [built]
2018-08-24T10:06:37.917151+00:00 app[web.1]: + 1784 hidden modules
2018-08-24T10:06:37.917126+00:00 app[web.1]: [../node_modules/webpack-dev-server/client/index.js?http://localhost:24282] (webpack)-dev-server/client?http://localhost:24282 7.93 kB {30} [built]
2018-08-24T10:06:37.917152+00:00 app[web.1]: webpack: Compiled successfully.
2018-08-24T10:06:37.917142+00:00 app[web.1]: [../node_modules/webpack/hot/dev-server.js] (webpack)/hot/dev-server.js 1.61 kB {30} [built]
2018-08-24T10:06:37.917150+00:00 app[web.1]: [./index.js] ./src/index.js 848 bytes {30} [built]
2018-08-24T10:06:44.847917+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-08-24T10:06:44.847917+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-08-24T10:06:44.963250+00:00 heroku[web.1]: Process exited with status 137
2018-08-24T10:06:44.977771+00:00 heroku[web.1]: State changed from starting to crashed
When initially searching for an answer, the most common response was: because I was hard setting the port instead of using process.env.PORT, but I've now changed that in the webpack settings:
return {
context: this.srcPathAbsolute,
devtool: 'eval',
devServer: {
contentBase: ['./public/', './src/'],
publicPath: '/assets/',
historyApiFallback: true,
hot: true,
inline: true,
port: process.env.PORT || 3000
But Heroku still shows this crash report. Every time it does show, however, the app is now using a different port- meaning it's now being set by Heroku.
The build time of webpack is 50s and I was wondering if that was the problem. Is it building too slow and then afterwards not having enough time to bind to a port before the 60s Heroku limit is up?
Honestly not really sure where to go from here, before hacking through files and changing the structure of the app for efficiency (although not a bad thing to do) I wanted to know if I was on the right trail. Would hate to change things in the app and accidentally create more problems when not solving the initial problem that was the most pressing.
If you have any suggestions, really would like to hear.
Thanks for your time.
Node: v8.11.3
Yarn: 1.6.0
Webpack: ^3.5.6
It looks like you're trying to run heroku in a development environment. You'll want to make sure that your environment is set to production and that you get web pack to compile all your assets.
The first line of the heroku output says webpack-dev-server --hot --open which suggests you're trying to use the web packer dev server in production which, as the name suggests, probably won't work.
This might help? https://www.thegreatcodeadventure.com/deploying-react-redux-to-heroku/

Resources