App.jsx line 11 is throwing an error due to an undefined property 'TodoComponent'

While attempting to style a ReactJS component, I encountered an error in my browser's development console:

App.jsx:11 Uncaught TypeError: Cannot read property 'TodoComponent' of undefined at App.render (App.jsx:11)

I have tried importing using the following syntaxes:

In App.jsx:

import {styles} from ...
import {styles as styles} from...

In styles.js :

export default styles... 
export styles...

All have failed.

Here is my directory tree structure:

src content directory - ls :
App.jsx  styles.js

Here is my App.jsx code snippet:

import React from "react";
import { render } from "react-dom";
// Import the styles
import {styles} from "./styles.js";


class App extends React.Component {

  render() {
    return (
    <div style={styles.TodoComponent}>
(...)

And here is my style.js code snippet:

var TodoComponent = {
      width: "300px",
      margin: "30px auto",
      backgroundColor: "#44014C",
      minHeight: "200px",
      boxSizing: "border-box"
    };

    var styles = {


    TodoComponent: TodoComponent,
( other styles...) 
    };

This is my webpack.config.js configuration:

var webpack = require("webpack") ;
var path = require("path") ;
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports= {
mode: "development",
devtool : "source-map",
context : __dirname + "/src",
entry : { app : __dirname + "/src/App.jsx" },
output : { path: path.resolve(__dirname, "public/"),
          filename : "frontend.bundle.js"
},
module: {
   rules: [ {
     test: /\.js|jsx$/,
     exclude: /node_modules/,
   include: path.resolve(__dirname, "src"),
     use: [
       {
   loader: 'babel-loader',
   options: {
     presets: ["es2015", "stage-1", "react"]
   }
       }
     ]
   },
 {
 test: /\.css$/,
 use: [
   { loader: 'style-loader' },
   {
     loader: 'css-loader',
     options: {
       modules: true
     }
 }
 ]}
]},


optimization : {

 splitChunks: {
     chunks: "async",
     minSize: 3000,
     minChunks: 1,
     maxAsyncRequests: 5,
     maxInitialRequests: 3,
     automaticNameDelimiter: "~",
     name: true,
     cacheGroups: {
   vendors: {
       test: /[\\/]node_modules[\\/]/,
       priority: -10
   },
     default: {
       minChunks: 2,
       priority: -20,
       reuseExistingChunk: true
   }
     }
 }
},
devServer: {
  proxy: {
  "/api": "http://localhost:7000"
},
 contentBase: path.resolve(__dirname, "public/"),
 open : true
}
};

Configuration in config.babelrc:

{
  "presets": ["env", "react", "stage-0"]
}

Answer №1

To make it available elsewhere, you must export the following:

var TodoStyle = { width: "300px", margin: "30px auto", backgroundColor: "#44014C", minHeight: "200px", boxSizing: "border-box" };

export const customStyles = { TodoStyle: TodoStyle, };

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

I want to showcase the numbers that have been clicked alongside the operator symbol that was clicked, and then reveal the result once the equals button is clicked

My coding issue arises when trying to perform calculations with more than two numbers. It works fine with only adding two numbers, but once I try to add multiple numbers, the functionality gets messed up. I intended for all the numbers and operator signs ...

Issue with react-table: unable to display server-side data in table when implementing manual pagination, filtering, and sorting

I've encountered an issue trying to display data from the backend (Python API) in react-table manually. Despite going through the documentation, I'm struggling to implement the example provided here: The peculiar problem is that I can only see d ...

Unusual ways that backgrounds and borders behave while incorporating CSS transitions for changes in height, positions, and transformations

I was under the impression that I had come up with a brilliant idea... I wanted to create a button with a hover effect where the background would do a wipe transition (top to bottom, left to right) using soft color transitions. My plan was to achieve this ...

The functionality of disabling autocompletion in Material UI input fields appears to be ineffective

I am currently using the Input field component from material-ui in conjunction with react. I have been attempting to disable autofill for all the fields, and despite trying several different solutions, none of them seem to be functioning properly. Here are ...

Encountering a Node.js error when executing the JavaScript file

When I try to run my Node.js application using the command "node main.js" in the terminal, I encounter an error saying "Error: Cannot find module 'D:\nodeP\main.js'". This is confusing for me as I have set the environment variable path ...

Tips for positioning the Google Custom Search bar

I am looking to position the Google custom search box on the left side of my website. Currently, I am using a website builder called imxprs and have implemented this code for my custom search box. <script> (function() { var cx = '013012 ...

What is the best way to implement a transaction fee when a specific function is triggered within my contract?

Consider this scenario: whenever a user successfully performs a contract function that calculates the sum of two numbers, I want to impose a 1% ETH fee that is transferred to a separate account from the contract. Although my current method "works", it is n ...

The government fails to compute the updated amount

Can anyone assist me with this problem? I am facing an issue where the second state is not updating based on the changes in the first state. Specifically, in the code snippet below, the setTotalPrice function does not receive the correct value of ingredie ...

Issues with responsive design

Frontend mentor projects have been a tricky challenge for me lately, especially when it comes to serving images of different viewport sizes on desktop. I've tried using the picture element and specifying at what width the image should be served, but f ...

What are the steps for configuring i18n translated URL paths in Next.js?

I have successfully implemented multi-language support on my website using Next.js i18n-routing. When I create a file in /pages/about.js, the URLs are generated based on my locale settings: EN -> /about DE -> /de/about ES -> /es/about Everything ...

Experiencing a problem with NextAuth on Vercel, I'm encountering a server error that needs to be resolved

I utilized Google as an authentication provider with NextAuth. I set up all necessary environment variables for both production and development environments. While it functions flawlessly in development mode on my local machine, I encounter the error "Serv ...

ReactJS.NET - Element isn't included in the document object model

I'm currently following a guide on ReactJS.NET and hit a roadblock while trying to incorporate the Hello World component (Here). Despite successful compilation with no errors, I am unable to see the component rendered. Below are snippets of the rele ...

What methods are available to create distinctive, shareable links akin to those utilized by Zoom and Google Hangouts?

I'm currently developing a group video chat app and I'm facing the challenge of generating distinct shareable links for every chat room created. Can anyone guide me on how to accomplish this? My aim is for users to easily join the chat room when ...

Building a Next.js application that supports both Javascript and Typescript

I currently have a Next.js app that is written in Javascript, but I am looking to transition to writing new code in Typescript. To add Typescript to my project, I tried creating a tsconfig.json file at the project root and then ran npm install --save-dev ...

Steps to Hide a Material-UI FilledInput

Trying to format a FilledInput Material-ui component to show currency using the following package: https://www.npmjs.com/package/react-currency-format Various attempts have been made, but none seem to be successful. A codesandbox showcasing the issue has ...

conceal the bootstrap navigation bar while the page is being

Struggling to toggle a Bootstrap navbar on scroll? Need some guidance from the pros out there. I admit, my Bootstrap and jQuery skills are pretty basic. The browser console doesn't throw any errors, and I've experimented with fadeIn, fadeOut, add ...

Adjust the background of the page at regular intervals

I currently have: <script type='text/javascript'> var imageID=0; function changeimage(every_seconds){ //change the image if(!imageID){ document.getByTagName("body").src="icwXI.jpg"; imageID++; } else{if(imageID==1){ document.ge ...

Issue with playing audio file using HowlerJS

Having trouble playing a .mp3 file in my project directory with Howler. I'm not sure if there's an error in my src. When I tried playing an online hosted audio file, it worked fine. I've placed the audio file in the same directory as Slideon ...

Unable to successfully cancel requestAnimationRequest in a React component when using hooks

I'm currently working on a progress bar project where I aim to halt the animation (using cancelAnimationRequest) once it reaches a specific value (10, 100, ... N) and reset it back to 0. Unfortunately, in my existing code, although it resets to 0, th ...

Expanding the `div` element to visually occupy the entire vertical space

I'm facing a design challenge with my webpage layout. I have a fixed header and footer, but I need the content section to dynamically adjust its height between the two. The goal is to fill the remaining vertical space with a background-image in the co ...