Can anyone help me with fixing the error message 'Cannot assign to read-only property 'exports' of the object' in React?

Recently, I decided to delve into the world of React and started building a simple app from scratch. However, I have run into an issue that is throwing the following error:

Uncaught TypeError: Cannot assign to read-only property 'exports' of object '#' at Module../src/app/about.js (bundle.js:2081) at webpack_require (bundle.js:724)

about.js

var React = require("react");
var createReactClass = require("create-react-class");
import { Link } from "react-router";

var About = createReactClass({
  render: function() {
    return(
        <Link to={"/"}>Home</Link>
    );
  }
});

module.exports = About;

webpack.config.js

var path = require('path');

module.exports = {
  entry: path.resolve(__dirname, 'src') + '/app/index.js',
  output: {
    path: path.resolve(__dirname, 'dist') + '/app',
    filename: 'bundle.js',
    publicPath: '/app/'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        include: path.resolve(__dirname, 'src'),
        loader: 'babel-loader'
      },
      {
        test: /\.css$/,
        loader: 'style-loader!css-loader'
      },
      {
        test: /\.(jpe?g|png|gif|woff|woff2|eot|ttf|svg)(\?[a-z0-9=.]+)?$/,
        loader: 'url-loader?limit=100000'        
      }
    ]
  }
};

package.json

  "devDependencies": {
    "babel-core": "^6.16.0",
    "babel-loader": "^6.2.5",
    "babel-preset-es2015": "^6.16.0",
    "babel-preset-react": "^6.16.0",
    "create-react-class": "^15.6.3",
    "css-loader": "^2.1.1",
    "style-loader": "^0.23.1",
    "webpack": "^1.13.2",
    "webpack-dev-server": "^1.16.1"
  }

.babelrc

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ]
}

It seems like the issue may be related to my module.exports

I would greatly appreciate any assistance with this problem.

Answer №1

Switch things up by opting for this alternative at the beginning of your document, in place of the typical import approach:

const { Link } = require("react-router");

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

communicating between a server using node.js and a client using python or node.js using the protobuf protocol

I'm currently delving into the protobuf protocol and I've encountered an issue where the server (node js) and client (python) are experiencing difficulties exchanging messages. However, there seems to be no problem when it comes to communication ...

Which is the Better React Entry Point: Index.html or index.js? And where exactly can we find the Node.js

After doing some research online, I came across conflicting information regarding the entry point for a react app. One source claimed that index.html serves as the entry point, while another stated that index.js is actually the main entry point for both Re ...

How can the value attribute be obtained from the click class?

$(document).on('click','.edit', function(){ var appid = $(this).getAttribute('value'); I am trying to figure out how to save the value of the "value" attribute for an image with the edit class. Can anyone help me with thi ...

Temperature is not linked to the user. Error in Sequelize when attempting eager loading

Within my application, users have the ability to log multiple temperature readings. However, each temperature record should be associated with only one user. I am encountering an error stating 'User is not associated with Temperature' while attem ...

Move the div in an animated way from the bottom of the screen to the right

I am facing an issue with the image animation in my project. Currently, the image moves from the bottom to the left corner, but I want it to move from the bottom to the right corner instead. I have attempted using the transform translate property to achiev ...

Unleash the Power of Animating Your Active Tabs

Is there a way to create animated tabs that slide in when clicked? I've experimented with using transition code but haven't quite achieved the desired effect yet. This is what I currently have: [data-tab-info] { display: non ...

What is the best way to assign a distinct index value to each object in an array

When I use the function below to add an index to each array object, all IDs end up with the same value when I check console.log: var foo = [...this.props.articleList]; foo.forEach(function(row, index) { row.id = index+1; }); console.log(foo); My des ...

Having trouble executing a query in Node.js with Sequelize and Passport.js when trying to register a new user

Here is the challenge I am facing: I am working with 3 models: users, favorites, and cryptocoins. 'use strict'; const { Model} = require('sequelize'); module.exports = (sequelize, DataTypes) => { class Cryptocoin extends Model { ...

Implementing a loading spinner in React Native until the component is fully mounted

I am dealing with a List component that takes some time to load. I am trying to display a spinner until the component is loaded and mounted, but all my attempts have been unsuccessful. Here is the approach I am currently attempting: class List extends R ...

Is it possible to circumvent making a double-API call using the getServerSideProps feature in NextJS?

Exploring the workings of NextJS' getServerSideProps, I've noticed an interesting pattern. Upon initially loading a page, the content is fully hydrated. However, upon navigating to a new page, an API call is triggered to fetch JSON data that will ...

Is there any way to remove the two default aspNetHidden Divs in asp.net web forms?

After creating an empty webform page in asp.net, the generated code looks like this: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Threetier.WebForm1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org ...

Error: Unable to locate font in the VueJS build

Within my config/index.js file, I have the following setup: ... build: { index: path.resolve(__dirname, 'dist/client.html'), assetsRoot: path.resolve(__dirname, 'dist'), assetsSubDirectory: 'static', assetsPub ...

Display every div element if none of the links have been clicked

On my webpage at url.com/yourfirstpage/, all div elements are hidden by default with a display:none property. If we specifically target #sec1 by going to url.com/yourfirstpage/#sec1, only sec1 is displayed while the others remain hidden. But what if we acc ...

Building a loading spinner component in a react-native project

I have successfully implemented a loading spinner that is currently being used in various components of my React project. However, as I am now working on a react-native version of the application, I am faced with the challenge of recreating this loading sp ...

What is the correct way to utilize ng-if/ng-show/ng-hide to hide or show HTML elements within the app.run function

I am currently working on developing an app that loads views correctly. HTML: <body> <loading outerWidth='1000' outerHeight='1000' display='isReady'></loading> <div class='wrapper' ng-sho ...

Determine whether a specific key exists in the formdata object

Can I check if a key in the formdata object already has a value assigned to it? I am looking for a way to determine if a key has been previously assigned a value. I attempted something like this but did not get the desired outcome data = new FormData(); ...

Tips for ensuring old logs do not display on Heroku Logs

I'm puzzled as to why my heroku logs command keeps showing old logs. Attempting to resolve this issue, I tried: heroku drains heroku logs However, the logs still display outdated information: app[api]: Release v1 created by user <a href="/cdn-c ...

Can Angular 4 experience race conditions?

Here is a snippet of my Angular 4 Service code: @Injectable() export class MyService { private myArray: string[] = []; constructor() { } private calculate(result): void { myArray.length = 0; // Perform calculations and add results to myAr ...

Changing the shape of a background using CSS when hovering

My Bootstrap navigation has a unique setup, as shown below. I've observed that many users tend to only interact with the headings and ignore the submenus where the actual products are located. To address this issue, I want to change the design of th ...

Exploring Nested Views in a MEAN Application using UI Router

I am currently developing a MEAN application and struggling to get my ui-router functioning correctly. Within my index.html template, I have loaded all the necessary javascript and css for my application such as angular, jquery, angular-ui-x, bootstrap. I ...