The final version of the React App is devoid of any content, displaying only a blank page

As a beginner in learning React, I must apologize for any basic issues I may encounter.

I recently created a shoe store App (following this helpful tutorial on React Router v6)

Everything seems to be working perfectly in the development build of my app.

https://i.stack.imgur.com/6YwwH.gif

However, when I create a production build (yarn build) and serve it using npx serve -s build, all I see is an empty page.

https://i.stack.imgur.com/BbJYF.png

The console throws an error stating that the shoeData object (which is a JavaScript object stored in a separate file called shoeData.js with named export) is not defined. This error did not occur in the development build. Interestingly, just before this error in the production build, an array was logged twice using the following code snippet:

console.log(Object.keys(shoeData).filter((productId) => shoeData[productId].featured));

Considering that the above code successfully utilizes the shoeData object initially, it appears that the object should be accessible to the component.

I even tried adding

"homepage": "."
in the package.json file, as some have suggested this could resolve similar issues. However, this did not work in my case.

You can find the complete project on GitHub here

Your assistance in resolving this issue would be greatly appreciated

Answer №1

From the URL, it appears that there is a ReferenceError stating that shoeData is not defined. This issue needs to be addressed promptly.

I am currently investigating the cause behind this error by cloning the repository.

Answer №2

I noticed something odd - it seems better to pass a string to src instead of requiring a file.

After cloning the repository, I verified that the issue was indeed caused by the require() statement.

Here are the steps to resolve this:

  1. Move the contents of images/ into the public/ folder
  2. Replace all instances of require('...').default with the image URL format, like
    /images/${shoeData[productId].gender}/${productId}/01.jpg
  3. Delete the homepage field from the package.json file

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

Error: The value for 'prepareStyles' property is undefined and cannot be read

Can anyone provide some guidance on this code snippet? I am struggling to understand the error message I am receiving. import React, {PropTypes} from 'react'; import TransactionListRow from './TransactionListRow'; import {Table, TableB ...

Can the react admin pagination for the List Component be customized to include an input that allows users to select their desired page number?

Is it possible to override the standard Pagination in React Admin's List Component and replace the "..." with an input field where users can enter a page number directly instead of clicking on buttons? After some research, it seems like this may not ...

Combining various data types within a single field in BigQuery

Is it feasible to specify a table schema with a field that allows for multiple data types? For instance: BIGQUERY TABLE SCHEMA schema: [{ name: 'field1', type: 'string', }, { name: 'field2', type: &apo ...

Aligning images with absolute CSS to text that is wrapping positions the images perfectly alongside the text content

My webpage has a long content section that resizes based on the browser width. Here's an example: <h1 id="loc1">Title</h1> <p>bodycopy bodycopy bodycopy bodycopy bodycopy bodycopy bodycopy bodycopy bodycopy bodycopy bodycopy bod ...

Creating state in ReactJS without relying on the constructor function

I have come across some ReactJS tutorials where the component state is initialized directly without the use of a constructor, like in the example below. class App extends React.Component { state = { text: 'hello world' } render() { ...

Utilize a specific hook once certain conditions are met

I am currently developing a Quiz application using react and typescript. To manage the functionality and pass it to the children components, I have implemented a quiz context provider. Within my quiz provider, I utilize a custom hook called useQuiz which ...

Where to Locate a String Excluding <a> Tags?

I'm in the process of writing a JavaScript code that will scan an HTML document and identify all occurrences of a specific keyword that are NOT contained within a link, meaning not under an <a> tag. To illustrate this, let's examine the fol ...

Expanding beyond boundaries: MUI Autocomplete in React surpassing the container dimensions

I am currently using the MUI Autocomplete feature and I'm encountering an issue where it extends beyond the container bounds. Specifically, I have AutoComplete set up within a <Grid> with the limitTags option enabled. Whenever I click on the aut ...

Issue: tanstack_react_query's useQuery function is not recognized

Error: (0 , tanstack_react_query__WEBPACK_IMPORTED_MODULE_3_.useQuery) is not a function While implementing data fetching in my Next.js project using @tanstack/react-query, I encountered the above error message. Below is the code snippet where the issue ...

Trouble with passing a nodejs variable into a nested function

I've been working on the code below but I'm having trouble getting the inner function .each to successfully call res.write with the results from the MongoDB query. At first, I thought the issue might be related to the variable res not being glob ...

Tips for modifying the status of a single component within a v-for loop without impacting other components

I am encountering an issue with my childComponent that is dynamically rendered using v-for within the parentComponent. The Parent component contains logic to fetch data from the database and display it on the screen. The fetch request query is dependent on ...

Implementing Dynamic Passing of Link Element Value to a Function in jQuery

I'm working with a link element that has its value set dynamically through asynchronous means. This label's value will initially be null until it is asynchronously set by an ajax call. <a href="#" onclick="myFunction(**I want to pass the lab ...

Steps for inserting buttons into rows of a material-ui data grid

I'm facing an issue while trying to add buttons in each row of the material-ui data grid. Instead of displaying the button, it shows [object Object]. You can see the output in the image linked below. Below is the code snippet I am using: import { D ...

There was an AJAX post error that occurred due to the refusal to set an unsafe header with the name "Connection"

My custom ajax function sends data to a PHP file, but I'm encountering two errors each time the data is posted: Refused to set unsafe header "Content-length" Refused to set unsafe header "Connection" Here is my code: function passposturl(url1 ...

The phenomenon of an invisible Absolute or relative position leading to grid components overlapping in Next.js

I've been struggling with this issue for over 48 hours now. I've attempted to troubleshoot by commenting out everything except the affected components and even swapping entire components around, but the problem persists. Oddly enough, rearranging ...

Incorporating an HTML page into a dialog using AngularJS: A step-by-step guide

Is it possible to dynamically change the content of a dialog by updating the URL? I have multiple HTML pages that I want to display in my dialog by simply changing the URL. <md-button ng-click="showDialog($event,'myurl/page-1.html')">Show ...

Tips for sending data through AJAX before the browser is about to close

My issue is with a javascript function that I've called on the html unload event. It seems to be working fine in Google Chrome, but for some reason it's not functioning properly in Firefox and IE. <script> function fun() { ...

implement django self,pk post-save success function

It might seem unconventional, but I'm attempting to utilize a primary key (pk) in a success function to generate a href for loading. The pk will be new and generated by the save() method. What I would like to know is how to send the self.pk pack to t ...

Challenges with loading times in extensive AngularJS applications

We are currently tackling performance issues related to the loading time of our AngularJS application. The page takes a significant amount of time to load, and we are exploring potential causes for this delay. One factor that could be contributing to the ...

Creating a hierarchical JSON structure to populate a Handlebars template (HTML) for an iterative component, allowing for the display of three levels of interconnected

Currently, I am working on developing a mega menu component that involves three levels of content. Level 1 (L1): This level is displayed horizontally in a traditional navbar. When hovered over, it expands to reveal the mega menu. Level 2 (L2): These item ...