The Express/React application runs smoothly when tested locally, but encounters issues when deployed to Her

Update

I have made some changes to the Procfile in order to consolidate my components.

New Procfile Configuration:

web: npm run build-client && node server/index.js

Unfortunately, this has resulted in a significant delay in loading time for my application. The bundling process is taking too long, leading to a poor user experience. Is there a more efficient way to handle this situation?

If all else fails, I am wondering if there is a way to display a static page immediately with the message:

"Blame Heroku, not me"

====== Original Context =======

The application functions correctly when using heroku local and accessing localhost:8080. However, upon deployment with heroku open, the view fails to render. The console displays the following error message:

app.bundle.js:1 Uncaught SyntaxError: Unexpected token <

This bundle contains my React components, which are structured with webpack codesplitting to load dependencies at different points due to the combination of afront/three.js framework and React on the frontend. It's puzzling why it works fine locally but encounters issues during deployment.

index.html

I have organized some JS modules by aframe/three components within index.bundle, while all of my react components reside in app.bundle

<head>
  <meta charset="utf-8">
  <title>Faceoff!</title>
  <script src="./commons.js"></script>
  <script src="./index.bundle.js"></script>
  <script src="//cdn.rawgit.com/donmccurdy/aframe-extras/v3.13.1/dist/aframe-extras.min.js"></script>
  <style> ... </style>
</head>

<body>
  <div id="app"></div>
  <script src="./app.bundle.js" defer></script> 
</body>

webpack.config.js

'use strict'
const webpack = require('webpack')
const path = require('path')

const extractCommons = new webpack.optimize.CommonsChunkPlugin({
  name: 'commons',
  filename: 'commons.js'
})

const config = {
  context: path.resolve(__dirname, 'client'),
  entry: {
    index: './index.js',
    app: './app.jsx'
  },
  output: {
    path: path.resolve(__dirname, 'public'),
    filename: '[name].bundle.js'
  },
  devtool: 'source-map',
  resolve: {
    extensions: ['.js', '.jsx']
  },
  module: {
    loaders: [
      {
        test: /jsx?$/,
        include: path.resolve(__dirname, 'client'),
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015']
        }
      }
    ]
  },
  plugins: [
    extractCommons
  ]
};

module.exports = config

index.js

This file contains the server-side code for the application. Posting this here as others have found solutions around this area.

'use strict'
const express = require('express');
const path = require('path');
const app = express();

const production = process.env.NODE_ENV === 'production';
const port = production ? process.env.PORT : 8080;

var publicPath = path.resolve(__dirname, '../public');

app.use(express.static(publicPath));

app.get('/', (req, res) => {
  res.sendFile(path.resolve(__dirname, '..', 'index.html'))
})

app.listen(port, () => {
 console.log(`Virtual Reality Enabled On Port ${port}`);
});

Answer №1

When running your npm script called build-client, which builds your webpack bundle, the bundles are found in a directory named public and all file names end with .bundle.js. In order to properly configure your Procfile, you should update it to:

web: npm run build-client && node public/index.bundle.js

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

Troublesome issue with Three.js cubeCamera and envmap functionality not functioning

Hello, I am currently facing two issues with the cubecamera in the three.js plugin. Every time I try to set up a cubecamera, cubeCamera = new THREE.CubeCamera( 1, 100000, 256, 128 ); //cubeCamera.renderTarget.minFilter = THREE.LinearMipMapLinearFilter; c ...

Is it possible to update the page title with JQuery or JavaScript?

Is it possible to modify the page title using a tag inside the body of the document with jQuery or JavaScript? ...

GIT: Relocating all items from a subfolder within a parent directory to the parent directory itself

Just starting out with Github and I'm facing some challenges. I uploaded my Django app to Github for use on Heroku. Although I successfully added files and folders on the web interface of Github, I realized that I made a mistake in uploading some fol ...

What is the best approach to detect multiple .change() events on elements that are dynamically updated through AJAX interactions?

Here is my first question, and I will make sure to follow all the guidelines. In a PHP page, I have two select groups, with the second group initially disabled. The first select group is named "yearlist", while the second select group is named "makelist" ...

Dispatch a post request from the client to node.js

As I dive into learning about node.js, I decided to create a simple guestbook application. This app consists of a comment form and a display of previous comments. Currently, the app operates solely on the client side with items being stored in local storag ...

Problem with Vue JS Hooper Image Slider (integrated into NuxtJS application)

Issue with Loading Images I encountered a problem while using the carousel feature in this GitHub project (). The images in the carousel do not display on the first load; instead, a loader animation image appears. However, upon refreshing the page, the ca ...

Issue with click events not registering on iOS devices when clicking on the document body

I recently added a side navigation bar to one of my websites and encountered an issue with hiding it on body click. I attempted to resolve the problem by using the following code snippet: jQuery(document.body).on('click', function (e) { ...

Unable to access object key data from JSON-SERVER

I am currently attempting to send a GET request to json-server in order to retrieve data from a nested object. However, the response I am receiving is empty instead of containing the desired data key. After thoroughly reviewing the documentation, I could ...

ASP TextChanged event is not triggering unless the user presses the Enter key or tabs out

My code is functioning correctly, however, the TextChanged event is triggered when I press enter or tab, causing my code to execute. I would like to be able to search for a record without having to press enter or tab. ASP: asp:TextBox ID="txtNameSearch ...

JavaScript substring() function in clone is experiencing an error

I am currently working on a JavaScript function that determines whether a specific substring is present in a larger main string. For instance, if the main string is "111010" and the substring is "011," the expected result should be false since the substr ...

Converting Node Server code into promises

Struggling with a sequencing problem in my node application where I need to set up a chat room. The setup requires three components: 1.) server.js, 2.) RoomHandler.js, and 3.) DBService.js. When a user triggers the createRoom action, it should return the ...

Exploring the intricacies of backbone data modeling: mastering the art of data

Greetings everyone, I am delving into the world of Backbone and JavaScript. My data.json file is structured as follows: { "locations": [ {address:"2222", town:"Dallas"},{address:'3333', town:"Houston"},{}.... ], "items": [ {title:"shirt", ...

Ways to retrieve a class list of a tag located within a div by clicking on the div, rather than the tag itself

I have 2 divs with an a tag and an i tag enclosed within them. I am using an onclick function, but it does not require writing the function itself. You can use something like getting elements on click of this item and then finding a certain class within th ...

Is it possible to import files in Vue JavaScript?

I want to incorporate mathematical symbols from strings extracted from a JSON file. While it seems to work perfectly on this example, unfortunately, I encountered an issue when trying it on my own machine. The error message 'Uncaught (in promise) Refe ...

Using JavaScript to implement Gzip compression

As I develop a Web application that must save JSON data in a limited server-side cache using AJAX, I am facing the challenge of reducing the stored data size to comply with server quotas. Since I lack control over the server environment, my goal is to gzip ...

Strategies for implementing classes in Typescript

I've been working on incorporating more classes into my project, and I recently created an interface and class for a model: export interface IIndexClient { id?: number; name?: string; user_id?: number; location_id?: number; mindbody_id?: nu ...

Fixing the Angular2 glitch: 'Uncaught TypeError: Cannot read property 'apply' of undefined'

Seeking solutions: How can I fix the "Uncaught TypeError: Cannot read property 'apply' of undefined" error that keeps showing up in the console of my Angular2 application? Any helpful insights are appreciated! ...

Mongoose: Unable to fetch item using its specific identification - Error 404

I've been attempting to fetch objects from MongoDB using Mongoose, but I keep encountering a 404 error. router.get('/blogs/:id', function(req, res){ console.log('trying to get one blog post by id'); Blog.findOne({ _id: req.para ...

Assign a value to the cookie based on the input from the form

I recently asked a similar question, but it seems like I missed providing some context, which is why I couldn't get it to work. My goal is to set a cookie value of a form entry when clicking on it (using the carhartl jquery plugin), but nothing happen ...

Having issues with Craco not recognizing alias configuration for TypeScript in Azure Pipeline webpack

I am encountering an issue with my ReactJs app that uses Craco, Webpack, and Typescript. While the application can run and build successfully locally, I am facing problems when trying to build it on Azure DevOps, specifically in creating aliases. azure ...