Having difficulty getting my create-react-app to display on Heroku

I successfully managed to get my react-app running smoothly on my localhost server. However, when I attempted to deploy it on Heroku, I encountered a problem. Upon visiting the app address provided by Heroku, all I see is a blank page with none of the components rendered. I have attached my server.js and App.js below. Please let me know if there is any other information I can provide for troubleshooting. Could it be possible that I am incorrectly linking something causing the components not to be included in the index.html build, or could there be another issue at play?

import React from 'react';
import {BrowserRouter as Router, Route, Switch} from 'react-router-dom'; 
import "./styles.css";
import Home from './Home';
import Locations from './Locations';
import ContactForm from './Contact';
import NoMatch from './NoMatch';
import AboutUs from './AboutUs';
import Menu from './Menu';
import { NavigationBar } from './components/NavBar';


function App() {

  return (
    <React.Fragment>
      <NavigationBar />
      
      
        <Router>
          <Switch>
            <Route exact path="/" component={Home} />
            <Route path="/aboutus" component={AboutUs} />
            <Route path="/locations" component={Locations} />
            <Route path="/contact" component={ContactForm} />
            <Route path="/menu" component={Menu} />
            <Route component={NoMatch} />
          </Switch>
        </Router>  
      
    </React.Fragment>
  );
}

export default App;

const express = require('express')
const path = require('path')
const app = express()

app.use(express.static(path.join(__dirname, 'build')));

app.get('/*', function (req, res) {
   res.sendFile(path.join(__dirname, 'build', 'index.html'));
 });

app.listen(process.env.PORT || 5000)

Any assistance would be greatly appreciated. You can view the deployed page by following this link: . If you feel like taking a look, perhaps it could shed some light on the situation. The only other potential issue I could think of is a misaligned file structure where the components are not being properly included.

Answer №1

When deploying both your backend and frontend simultaneously, it is essential to include a Heroku post build script in the backend package.json file.

"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix ../FRONTEND FOLDER_NAME && npm run build --prefix npm start --prefix ../FRONTEND FOLDER_NAME"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging React hooks to combine an array and an object within an array

Struggling to incorporate an array and an object into another array. This is the setup in my constructor: const [dashboard, setDashboard] = useState({ loading: true, data: [], address: '' }) This is how I envision the final data structure: { ...

Retrieve a text file using FTP asynchronously and utilizing Promises in Node.js and AWS Lambda

Utilizing a single Node module called basic-ftp, I am tasked with downloading a txt file in AWS Lambda and storing it in the /tmp/ directory within the Lambda function. The goal is to manipulate the txt file and its contents outside of the FTP function. ...

Is there a standard event triggered upon the closing of a browser tab or window?

Does React have a built-in event that is triggered when a browser tab or window is closed? If it does, does it have support across different browsers? ...

What is the best way to incorporate a transition effect into a flex item with a specified max-width, where the width adjustments are managed by a child div?

The example below demonstrates a situation where the child's width grows with a smooth transition, but the parent's width abruptly changes! What I aim for is to have both the child's width and the parent's width transition smoothly. I ...

Discover the secrets of accessing two distinct objects returned by a single REST URL with Backbone

I am working with a REST URL that looks like this: /users/<user_id>/entities This URL returns data containing 2 objects as follows: { "players": { "test_player2": { "_id": "test_player2", "user": "f07590 ...

Is it possible to manipulate a parent component's state with a child component?

I have been experimenting with Material UI's react modal to create a modal as my child component. In the parent component, I have set up a state that controls the visibility of the modal and added a button inside the modal to close it. However, this s ...

What is the proper way to connect my JavaScript code to my HTML form?

My JavaScript function is not working properly when I try to submit a form on my website. <form onsubmit="validateRegistration()"> <p> // Email registration <input type="text" id="e-mail" placeholder="Email" /> </p> ...

Discover how to utilize Express.js with MongoDB using the forEach method

I am facing a major issue. I need to go through a collection of results and for each set, I need to find one specific result. This is how it currently looks: router.get('/', function(req, res) { var floors = []; var rooms = []; req ...

The Slice method is malfunctioning after the array has been filtered

I am currently working on creating a news portal app using Next JS, Redux, mongoose, and Express. My Issue is: While I am able to filter specific items from an array successfully, I encounter problems when attempting to display a specific number of items, ...

Struggling to retrieve the Object from a JSON file located at a specific URL

Apologies if this comes across as naive, but my venture into javascript and json is just starting. I'm eager to access the JSON object from the twitter API after executing var myjson; $.getJSON('url of the Object', function(data) { ...

Can you stop a JavaScript event using another event?

Can you prevent a JavaScript event in the queue from being executed by another event? Situation: I have two ASP.Net controls, Age - TextBox Save - Button There are two JavaScript validation functions, ValidateAge() - verifies if the age is between ...

Transfer PHP's uniqid() function to real-time using JavaScript with jQuery

Seeking a compact JavaScript(jQuery) code snippet to achieve this: date("r",hexdec(substr(uniqid(),0,8))); Your assistance is highly appreciated. Thank you. ...

Understanding the data types of functions in TypeScript can be quite important for

What type of information is required after the colon : in this specific function? public saveHistory(log: String): "HERE!" { return async (req: Request, res: Response, next: NextFunction): Promise<Response | void> => { try { ...

Using jQuery to Save Data Locally in a JSON File

Just a heads up; all of my work is kept local. I've been on the hunt for ways to write to a JSON file from a JS script using jQuery. Many methods involve PHP, but I don't have much experience with that language and would prefer to avoid it for no ...

Using jQuery for dynamic string interpolation in input selection

Currently, I am attempting to choose an input within my dom and I am aware that it can be accomplished as follows: $("input[value='foo']") ...but, what if we were to use a variable instead? For example, if we have a variable x = 'foo' ...

There are certain lines of JavaScript/Node.js code that are failing to execute

app.get is not being executed. I have also attempted to include app.listen(3000). My goal is to retrieve the parameter passed from the first web page. This code is designed to fetch parameters sent by another web page and then construct a MySQL query and ...

Stopping a nodejs ajax request code once the response has been sent can be achieved by implementing

In the process of creating a user signup form in Nodejs with Express framework, Mongodb and Monk integration, I encountered an issue. While I successfully implemented the database insertion, I faced trouble when attempting to check if the entered email o ...

Retrieve information through an AJAX or JavaScript request and use it to fill the selected plugin's multiple selection feature

I have searched everywhere for a solution to this problem, but I haven't been able to find any helpful resources. I apologize in advance if this question has been asked before. What I need to do is to display the data from a JSON object that is fetch ...

A guide on sorting through categories in Angular 9

Having trouble filtering categories in a Webshop? I've been following a tutorial by Mosh but I can't seem to get it right. No error messages but nothing is being filtered or displayed. I'm brand new to Angular and/or typescript, so please be ...

What is the best method for transferring information in TwitterStrategy using PassportJS?

I am managing three different types of users: Viewer (click here to sign in: auth/v/twitter) Creator (click here to sign in: auth/c/twitter) Admin (click here to sign in: auth/a/twitter) In addition, I have 3 different database collections: c_view ...