Adrian
Adrian

Reputation: 3062

How do I solve Cannot assign to read only property 'exports' of object in react?

I am new to react and trying to build a simple app from scratch. I am encountering an error that says:

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"
  ]
}

I think this has something to do with my module.exports

Any help is greatly appreciated.

Upvotes: 1

Views: 5654

Answers (1)

Len Joseph
Len Joseph

Reputation: 1458

At the top of the file, instead of using import method, use this:

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

Upvotes: 3

Related Questions