Heroku "Application error" on a Django/React app - reactjs

I'm currently working on a to do list project for my studies and I was able to chose the technologies involved.
I decided to use Django, React, MongoDB for the app and Heroku for the hosting. I had previous experience with React MongoDB and NodeJS and managed to host the app on heroku very easily.
However with this new project I always get an "Application Error" whenever I try to access the website.
I struggled to find up to date information on how to properly host a Django/React app on Heroku and none of the answers I found solved my problem.
What concerns me the most is that the deployment log do not show any major issue during the build process :
> Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 356 bytes | 356.00 KiB/s, done.
Total 4 (delta 3), reused 0 (delta 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 16.x...
remote: Downloading and installing node 16.16.0...
remote: Using default npm version: 8.11.0
remote:
remote: -----> Restoring cache
remote: - npm cache
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote:
remote: added 1457 packages, and audited 1458 packages in 12s
remote:
remote: 205 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: 6 high severity vulnerabilities
remote:
remote: To address all issues (including breaking changes), run:
remote: npm audit fix --force
remote:
remote: Run `npm audit` for details.
remote:
remote: -----> Build
remote: Running build
remote:
remote: > frontend#0.1.0 build
remote: > react-scripts build
remote:
remote: Creating an optimized production build...
remote: Compiled with warnings.
remote:
remote: [eslint]
remote: src/components/AppNavbar.js
remote: Line 1:10: 'Collapse' is defined but never used no-unused-vars
remote: Line 53:19: The href attribute requires a valid value to be accessible. Provide a valid, navigable address as the href value. If you cannot provide a valid href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
remote: Line 57:25: The href attribute is required for an anchor to be keyboard accessible. Provide a valid, navigable address as the href value. If you cannot provide an href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
remote: Line 58:25: The href attribute is required for an anchor to be keyboard accessible. Provide a valid, navigable address as the href value. If you cannot provide an href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
remote:
remote: src/components/Body.js
remote: Line 13:6: React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array react-hooks/exhaustive-deps
remote:
remote: src/components/TaskElement.js
remote: Line 59:11: The href attribute is required for an anchor to be keyboard accessible. Provide a valid, navigable address as the href value. If you cannot provide an href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
remote: Line 65:13: The href attribute is required for an anchor to be keyboard accessible. Provide a valid, navigable address as the href value. If you cannot provide an href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
remote:
remote: Search for the keywords to learn more about each warning.
remote: To ignore, add // eslint-disable-next-line to the line before.
remote:
remote: File sizes after gzip:
remote:
remote: 89.81 kB build/static/js/main.67b777d4.js
remote: 27.94 kB build/static/css/main.fc8229bc.css
remote: 1.78 kB build/static/js/787.cda612ba.chunk.js
remote:
remote: The project was built assuming it is hosted at /.
remote: You can control this with the homepage field in your package.json.
remote:
remote: The build folder is ready to be deployed.
remote: You may serve it with a static server:
remote:
remote: npm install -g serve
remote: serve -s build
remote:
remote: Find out more about deployment here:
remote:
remote: https://cra.link/deployment
remote:
remote:
remote: -----> Caching build
remote: - npm cache
remote:
remote: -----> Pruning devDependencies
remote:
remote: up to date, audited 1458 packages in 3s
remote:
remote: 205 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: 6 high severity vulnerabilities
remote:
remote: To address all issues (including breaking changes), run:
remote: npm audit fix --force
remote:
remote: Run `npm audit` for details.
remote:
remote: -----> Build succeeded!
remote: -----> Python app detected
remote: -----> Using Python version specified in runtime.txt
remote: ! Python has released a security update! Please consider upgrading to python-3.8.13
remote: Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> No change in requirements detected, installing from cache
remote: -----> Using cached install of python-3.8.10
remote: -----> Installing pip 22.1.2, setuptools 60.10.0 and wheel 0.37.1
remote: -----> Installing dependencies with Pipenv 2020.11.15
remote: Installing dependencies from Pipfile...
remote: -----> Installing SQLite3
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 153M
remote: -----> Launching...
remote: Released v11
remote: https://task-list-manager-gf.herokuapp.com/ deployed to Heroku
remote:
remote: This app is using the Heroku-20 stack, however a newer stack is available.
remote: To upgrade to Heroku-22, see:
remote: https://devcenter.heroku.com/articles/upgrading-to-the-latest-stack
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/task-list-manager-gf.git
15c029d..a5e2c42 master -> master
The only errors displayed in this log are related to react and they do not prevent the app from working perfectly fine locally.
I figured the problem might reside in my settings.py file:
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '#######################################################""'
DEBUG = False
ALLOWED_HOSTS = ['localhost:3000/', '127.0.0.1', 'task-list-manager-gf.herokuapp.com/']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api.apps.ApiConfig',
'corsheaders',
'pymongo'
]
CORS_ORIGIN_ALLOW_ALL = True
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',
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
ROOT_URLCONF = 'backend.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'build')],
'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 = 'backend.wsgi.application'
# Database
DATABASES = {
'default': {
'ENGINE': '',
'NAME': '',
}
}
# Password validation
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
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = 'static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'build/static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
# Default primary key field type
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
The current file structure of my app looks like this :
Main project directory
There is a 'build' and 'staticfile' folder because I tried to use the python manage.py collectstatic command to see if the problem came from python not being able to access React files.
my requirement.txt is the following :
asgiref==3.5.2
backports.zoneinfo==0.2.1
Django==4.0.6
django-cors-headers==3.13.0
dnspython==2.2.1
gunicorn==20.1.0
pymongo==4.2.0
sqlparse==0.4.2
whitenoise==6.2.0
and my package.json file :
{
"name": "frontend",
"proxy": "http://localhost:8000",
"version": "0.1.0",
"private": true,
"dependencies": {
"#primer/octicons-react": "^17.3.0",
"#reduxjs/toolkit": "^1.8.3",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"bootstrap": "^5.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.2",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
After looking into the app log I found the error below. Heroku cannot find the gunicorn despite the package being referenced in the requirement.txt file.
2022-07-26T17:47:34.919084+00:00 heroku[web.1]: State changed from crashed to starting2022-07-26T17:47:44.388599+00:00 heroku[web.1]: Starting process with command `gunicorn backend.wsgi --log-file -`2022-07-26T17:47:45.219051+00:00 app[web.1]: bash: gunicorn: command not found2022-07-26T17:47:45.331605+00:00 heroku[web.1]: Process exited with status 1272022-07-26T17:47:45.370368+00:00 heroku[web.1]: State changed from starting to crashed2022-07-26T18:49:00.301044+00:00 heroku[web.1]: State changed from crashed to starting2022-07-26T18:49:10.354539+00:00 heroku[web.1]: Starting process with command `gunicorn backend.wsgi --log-file -`2022-07-26T18:49:11.240683+00:00 app[web.1]: bash: gunicorn: command not found2022-07-26T18:49:11.362628+00:00 heroku[web.1]: Process exited with status 1272022-07-26T18:49:11.551249+00:00 heroku[web.1]: State changed from starting to crashed2022-07-26T22:33:39.008533+00:00 heroku[web.1]: State changed from crashed to starting2022-07-26T22:33:51.671289+00:00 heroku[web.1]: Starting process with command `gunicorn backend.wsgi --log-file -`2022-07-26T22:33:52.841248+00:00 app[web.1]: bash: gunicorn: command not found2022-07-26T22:33:54.073693+00:00 heroku[web.1]: State changed from starting to crashed2022-07-26T22:33:52.982851+00:00 heroku[web.1]: Process exited with status 127
272022-07-26T17:47:45.370368+00:00 heroku[web.1]: State changed from starting to crashed
All the source code is available on my git : https://github.com/GuillaumeFavrot/TaskListManager.live
I'm running out of ideas so if you see something I'm missing that'd be great and let me know if more information is required.
Thanks!

Try setting allowed host in your settings.py to *

Related

react push to heroku and getting following errors

newbie here - first time trying to push react frontend to heroku. i have tried what heroku has asked for and is still not working. think i made it worse by implementing suggestions when googling...(btw i have this is my index.js file: import {Provider} from 'react-redux')
following list of errors
♥ git push heroku master
Enumerating objects: 39, done.
Counting objects: 100% (39/39), done.
Delta compression using up to 8 threads
Compressing objects: 100% (37/37), done.
Writing objects: 100% (39/39), 140.24 KiB | 6.37 MiB/s, done.
Total 39 (delta 5), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NPM_CONFIG_PRODUCTION=true
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote: NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 10.x...
remote: Downloading and installing node 10.16.3...
remote: Using default npm version: 6.9.0
remote:
remote: -----> Installing dependencies
remote: Installing node modules (package.json + package-lock)
remote:
remote: > core-js#2.6.9 postinstall /tmp/build_59a9e22c84972b1649248fcdd072b559/node_modules/babel-runtime/node_modules/core-js
remote: > node scripts/postinstall || echo "ignore"
remote:
remote:
remote: > core-js-pure#3.1.4 postinstall /tmp/build_59a9e22c84972b1649248fcdd072b559/node_modules/core-js-pure
remote: > node scripts/postinstall || echo "ignore"
remote:
remote: added 1386 packages from 676 contributors and audited 902051 packages in 34.626s
remote: found 2 vulnerabilities (1 high, 1 critical)
remote: run `npm audit fix` to fix them, or `npm audit` for details
remote:
remote: -----> Build
remote: Running build
remote:
remote: > kayaks#0.1.0 build /tmp/build_59a9e22c84972b1649248fcdd072b559
remote: > react-scripts build
remote:
remote: Creating an optimized production build...
remote: Failed to compile.
remote:
remote: ./src/index.js
remote: Cannot find module: 'react-redux'. Make sure this package is installed.
remote:
remote: You can install this package by running: npm install react-redux.
remote:
remote:
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! kayaks#0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the kayaks#0.1.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.P3JWe/_logs/2019-10-08T00_50_49_274Z-debug.log
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: Some possible problems:
remote:
remote: - Node version not specified in package.json
remote: https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote: - A module may be missing from 'dependencies' in package.json
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to kayaks-frontend.
remote:
package.json
{
"name": "kayaks",
"version": "0.1.0",
"private": true,
"engines": {
"npm": "6.11.3",
"node": "12.11.0",
},
"dependencies": {
"cuid": "^1.3.8",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-date-picker": "^7.8.1",
"react-datepicker": "^2.8.0",
"react-dom": "^16.8.6",
"react-dropdown-select": "^3.3.1",
"react-redux": "^7.1.1",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1",
"react-semantic-ui-datepickers": "^1.11.0",
"redux": "^4.0.4",
"redux-form": "^8.1.0",
"redux-thunk": "^2.3.0",
"semantic-ui": "^2.4.2",
"semantic-ui-calendar-react": "^0.15.2",
"semantic-ui-css": "2.4.1",
"semantic-ui-react": "^0.87.3",
"typescript": "^3.6.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Cannot find module: 'react-redux'. Make sure this package is installed
This is your problem. Have you installed this? Try running npm i and then deploying.
To host a create-react-app on Heroku you must serve the /build folder. You can do it very easily with a node.js express server.
First you'll need to install express so you can run npm i express --save or yarn add express.
Then just add a server.js file to the root of your project serving the /build folder as static content and routing all request to /build/index.html.
const path = require('path');
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.use(express.static(path.join(__dirname, 'build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'build/index.html'));
});
app.listen(port, () => {
console.log(`The server is running on port ${port}!`);
});
Lastly, you need to update your npm run start script to node server.js, and use react-scripts start only during development.
"scripts": {
"start": "node server.js",
"dev": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Heroku will run your npm run build and then your npm run start scripts when a new version is deployed.

Build fails when pushing to Heroku due to unexpected token in no-longer-existing file

I am making a webapp using a boilerplate i found online. I decided to use CanvasJS to display a graph, and it worked lovely after dropping the dependancies into an assets folder within my project. When I couldn't push to Heroku due to a failing build revolving around CanvasJS, I decided to switch to Recharts and delete all references to CanvasJS. When I push to Heroku now, I get the same error as before (seen below):
remote: > react-redux-boilerplate#1.0.0 build /tmp/build_8454890d5cf17da8345e5f577f4f5487
remote: > cross-env NODE_ENV=production webpack --config config/webpack.prod.babel.js --color -p --progress --hide-modules --display-optimization-b
ailout
remote:
remote: Hash: 90d3a9367d4988ba0f97
remote: Version: webpack 4.34.0
remote: Time: 18718ms
remote: Built at: 07/30/2019 2:48:43 AM
remote: 5 assets
remote: Entrypoint main = main.161cd093393cb111dcb1.js
remote:
remote: ERROR in ./assets/canvasjs/canvasjs.react.js 6:24
remote: Module parse failed: Unexpected token (6:24)
remote: File was processed with these loaders:
remote: * ./node_modules/babel-loader/lib/index.js
remote: You may need an additional loader to handle the result of these loaders.
remote: |
remote: | class CanvasJSChart extends React.Component {
remote: > static _cjsContainerId = 0
remote: | constructor(props) {
remote: | super(props);
remote: # ./app/containers/HomePage/PieChart.js 24:0-68 25:20-33
remote: # ./app/containers/HomePage/HomePage.js
remote: # ./app/containers/HomePage/index.js
remote: # ./app/containers/HomePage/Loadable.js
remote: # ./app/containers/App/App.js
remote: # ./app/containers/App/index.js
remote: # ./app/app.js
remote: # multi ./app/app.js
remote: Child html-webpack-plugin for "index.html":
remote: 1 asset
remote: Entrypoint undefined = index.html
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 2
remote: npm ERR! react-redux-boilerplate#1.0.0 build: `cross-env NODE_ENV=production webpack --config config/webpack.prod.babel.js --color -p --progress -
-hide-modules --display-optimization-bailout`
remote: npm ERR! Exit status 2
remote: npm ERR!
remote: npm ERR! Failed at the react-redux-boilerplate#1.0.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I completely deleted the canvasjs folder from within the assets folder, did npm uninstall canvasjs in case I installed it through npm, deleted PieChart.js from my HomePage folder, deleted the reference to it in the HomePage.js file, but I still get the same error. It's saying there's an unexpected token in a file that doesn't even exist anymore.
I've tried npm run build to get a clean build, but it did nothing. Why is it detecting a folder that doesn't exist?

Getting an error when trying to deploy a react app to heroku

I'm trying to learn how to deploy a react application to heroku, but I keep getting an error message whenever I do a test run.
I've been using the following commands to create a react app and deploy it to heroku:
$ npx create-react-app struttingpeacocks
$ cd struttingpeacocks
$ git init
$ heroku create struttingpeacocksapp --buildpack https://github.com/mars/create-react-app-buildpack.git
$ git add .
$ git commit -m "create-react-app"
$ git push heroku master
When I do this, though, the following code runs with an error message towards the end:
$ git push heroku master
Counting objects: 18, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (18/18), done.
Writing objects: 100% (18/18), 88.11 KiB | 3.26 MiB/s, done.
Total 18 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> React.js (create-react-app) multi app detected
remote: -----> Configure create-react-app build environment
remote: Using `NODE_ENV=development`
remote: =====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-multi.git
remote: =====> Detected Framework: Multipack
remote: =====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
remote: =====> Detected Framework: Node.js
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NPM_CONFIG_PRODUCTION=false
remote: NODE_ENV=development
remote: NODE_MODULES_CACHE=true
remote: NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote: engines.yarn (package.json): unspecified (use default)
remote:
remote: Resolving node version 8.x...
remote: Downloading and installing node 8.12.0...
remote: Using default npm version: 6.4.1
remote: Resolving yarn version 1.x...
remote: Downloading and installing yarn (1.12.1)...
remote: Installed yarn 1.12.1
remote:
remote: -----> Building dependencies
remote: Installing node modules (yarn.lock)
remote: yarn install v1.12.1
remote: [1/4] Resolving packages...
remote: error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.
remote: info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
remote:
remote: -----> Build failed
remote:
remote: ! Outdated Yarn lockfile
remote:
remote: Your application contains a Yarn lockfile (yarn.lock) which does not
remote: match the dependencies in package.json. This can happen if you use npm
remote: to install or update a dependency instead of Yarn.
remote:
remote: Please run the following command in your application directory and check
remote: in the new yarn.lock file:
remote:
remote: $ yarn install
remote: $ git add yarn.lock
remote: $ git commit -m "Updated Yarn lockfile"
remote: $ git push heroku master
remote:
remote: https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-an-outdated-yarn-lockfile
remote:
remote: ! Push rejected, failed to compile React.js (create-react-app) multi app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to struttingpeacocksapp.
remote:To https://git.heroku.com/struttingpeacocksapp.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/struttingpeacocksapp.git'
My package.json is the following code
{
"name": "struttingpeacocks",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.6.0",
"react-dom": "^16.6.0",
"react-scripts": "2.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
I could really use some help with this. Any advice would be greatly appreciated
You should to install this package .
npm i create-app-react
or
yarn add create-app-react
And add the version of node and npm to your package.js
`"engines": { "node": "YOUR_VERSION_OF_NODE",
"npm": "YOUR_VERSION_OF_NPM"}`,
You can find the version by putting node -v npm -v in the cmd
If you're using yarn, then update the yarn.lock file, commit it, and redeploy.
But if you are using npm, then update your package-lock.json try removing your 'yarn.lock' file, then try pushing your code again. Make sure either yarn.lock OR package-lock.json exists remotely, but not both.
Hope this helps.

npm ERR! missing script: build in REACT DEPLOYED IN HEROKU

I'm trying to deploy a project in Heroku with create-react-app using Node as my server and MongoDB for my database but I'm getting an error. this is my first to deploy a project with React. I have 2 package.json files. One for create-react-app the other is for my node server.
What I did was:
run the build in React,
commit,
create a Heroku app using heroku create -b https://github.com/mars/create-react-app-buildpack.git
I pushed it to Heroku master.
Here are the logs.
Counting objects: 203, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (187/187), done.
Writing objects: 100% (203/203), 191.40 KiB | 5.80 MiB/s, done.
Total 203 (delta 91), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> React.js (create-react-app) multi app detected
remote: -----> Configure create-react-app build environment
remote: Using `NODE_ENV=development`
remote: =====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-multi.git
remote: =====> Detected Framework: Multipack
remote: =====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
remote: =====> Detected Framework: Node.js
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NPM_CONFIG_PRODUCTION=false
remote: NODE_VERBOSE=false
remote: NODE_ENV=development
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 8.x...
remote: Downloading and installing node 8.11.4...
remote: Using default npm version: 5.6.0
remote:
remote: -----> Restoring cache
remote: Skipping cache restore (not-found)
remote:
remote: -----> Building dependencies
remote: Installing node modules (package.json + package-lock)
remote: added 85 packages in 3.391s
remote:
remote: -----> Caching build
remote: Clearing previous node cache
remote: Saving 2 cacheDirectories (default):
remote: - node_modules
remote: - bower_components (nothing to cache)
remote:
remote: -----> Pruning devDependencies
remote: Skipping because NODE_ENV is not 'production'
remote:
remote: -----> Build succeeded!
remote: =====> Downloading Buildpack: https://github.com/mars/create-react-app-inner-buildpack.git
remote: =====> Detected Framework: React.js (create-react-app)
remote: Writing `static.json` to support create-react-app
remote: Enabling runtime environment variables
remote: npm ERR! missing script: build
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /app/.npm/_logs/2018-09-04T05_56_24_845Z-debug.log
remote: ! Push rejected, failed to compile React.js (create-react-app) multi app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to klikie.
remote:
To https://git.heroku.com/klikie.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/klikie.git
this is my package.json in create-react-app
{
"name": "klikme",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:8000/",
"dependencies": {
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.5",
"styled-components": "^3.4.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
this is for my server dep:
{
"name": "klikme",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.3",
"mongoose": "^5.2.12",
"morgan": "^1.9.0"
}
}
I added this in my server too since its in the documentation:
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
So a couple of things I notice based on what you shared here. You are not using the engines section of your package.json file to specify the Node.js version to use on Heroku. It would look something like this:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": {
"node": "9.3.0",
"npm": "5.6.0"
},
You will also see the version of npm separated out above, Node.js comes bundled with npm, so most of the time you don’t need to specify a separate npm version. However, if you intentionally use a different version of npm locally, you can specify the same version of npm on Heroku.
Lastly, there are Heroku build steps and I do not see that in your main package.json file. Keep in mind that what I have written here does not apply to your create-react-app package.json file because that will be blown away when you deploy to Heroku. create-react-app will cease to exist in Heroku.
So for Heroku specific actions you will want to add something like this to your main package.json file:
"heroku-postbuild":
"NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
In regards to what you added in your server, try writing it this way:
if (process.env.NODE_ENV === 'production') {
// Express will serve up production assets
// like main.js or main.css
app.use(express.static('client/build'));
// Express will serve up the index.html file if
// it doesnt recognize the route
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
Also, I am assuming this is in your main index.js file and you should also have these two lines of code at the bottom of the file:
const PORT = process.env.PORT || 5000;
app.listen(PORT);

Issue in Hosting React App on Heroku

I am trying to host the react app in heroku...
I have created the app using create-react-app..And follow the following methods in hosting...
git init
heroku create $APP_NAME --buildpack https://github.com/mars/create-react-app-buildpack.git
git add .
git commit -m "Start with create-react-app"
git push heroku master
heroku open
But when I am trying to push the app to heroku it returns the following error...
remote: - htmlparser.js:235 new HTMLParser
remote: [build_4acd980d8a80e0486da141a82d0b3cee]/[html-minifier]/src/htmlparser.js:2 35:13
remote:
remote: - htmlminifier.js:946 minify
remote: [build_4acd980d8a80e0486da141a82d0b3cee]/[html-minifier]/src/htmlminifier.js :946:3
remote:
remote: - htmlminifier.js:1299 exports.minify
remote: [build_4acd980d8a80e0486da141a82d0b3cee]/[html-minifier]/src/htmlminifier.js :1299:10
remote:
remote: - index.js:296
remote: [build_4acd980d8a80e0486da141a82d0b3cee]/[html-webpack-plugin]/index.js:296: 16
remote:
remote: - util.js:16 tryCatcher
remote: [build_4acd980d8a80e0486da141a82d0b3cee]/[bluebird]/js/release/util.js:16:23
remote: - promise.js:512 Promise._settlePromiseFromHandler
remote: [build_4acd980d8a80e0486da141a82d0b3cee]/[bluebird]/js/release/promise.js:51 2:31
remote:
remote: - promise.js:569 Promise._settlePromise
remote: [build_4acd980d8a80e0486da141a82d0b3cee]/[bluebird]/js/release/promise.js:56 9:18
remote:
remote: - promise.js:614 Promise._settlePromise0
remote: [build_4acd980d8a80e0486da141a82d0b3cee]/[bluebird]/js/release/promise.js:61 4:10
remote:
remote: - promise.js:693 Promise._settlePromises
remote: [build_4acd980d8a80e0486da141a82d0b3cee]/[bluebird]/js/release/promise.js:69 3:18
remote:
remote: - async.js:133 Async._drainQueue
remote: [build_4acd980d8a80e0486da141a82d0b3cee]/[bluebird]/js/release/async.js:133: 16
remote:
remote: - async.js:143 Async._drainQueues
remote: [build_4acd980d8a80e0486da141a82d0b3cee]/[bluebird]/js/release/async.js:143: 10
remote:
remote: - async.js:17 Immediate.Async.drainQueues
remote: [build_4acd980d8a80e0486da141a82d0b3cee]/[bluebird]/js/release/async.js:17:1 4
How can I resolve this issue?
I just cloned your repo and tried npm install + npm run build. I found that npm run build fails locally. So, this is an error with the code, not with Heroku deployment.
The failure is from HTMLParser, so I looked at the public/index.html and found a heavily customized template.
To check if that public/index.html content was the problem, I replaced it with the default create-react-app HTML template code. Then, npm run build completed successfully.
So, it seems there is a problem with the validity of the HTML in your public/index.html which breaks create-react-app's template engine. I suggest running it through an HTML validator to find problems, or manually breaking the template into smaller testable pieces until you find the part that causes the build error.

Resources