Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot set property" error on React class component method #32

Closed
AndrewRayCode opened this issue Jul 26, 2016 · 16 comments
Closed

"Cannot set property" error on React class component method #32

AndrewRayCode opened this issue Jul 26, 2016 · 16 comments

Comments

@AndrewRayCode
Copy link

AndrewRayCode commented Jul 26, 2016

I'm guessing I'm missing something but not sure what.

My .babelrc:

{
  "presets": ["react", "es2015", "stage-0"],

  "plugins": [
    "transform-decorators-legacy"
  ],

  "env": {
    "development": {
      "plugins": [ "typecheck" ]
    }
  }
}

My webpack loader config:

{
    test: /\.jsx?$/,
    exclude: /node_modules/,
    loaders: [ 'react-hot', 'babel?presets[]=es2015&presets[]=react&presets[]=stage-0&plugins[]=transform-decorators-legacy' ]
}

My .eslintrc (I have no idea if both of these are needed):

  "parser": "babel-eslint",
  "settings": {
    "import/parser": "babel-eslint",

In my React component, I use the autobind decorator:

import autobind from 'autobind-decorator';

export default class Home extends Component {

    @autobind
    onPress() {}

}

But I get the runtime error:

makeAssimilatePrototype.js:21 Uncaught TypeError: Cannot set property onPress of # which has only a getter

@InfernoZeus
Copy link

Just started getting this issue as well - no idea what's triggered the change. The only thing I did was extract a class into its own file, but I don't think that caused it.

@AndrewRayCode
Copy link
Author

@InfernoZeus what version of React are you using? Wondering if component classes changed something internally recently. Or maybe how Babel handles classes?

For me:
React 15.2.1
babel-core 6.11.4

@InfernoZeus
Copy link

I'm using the same version of React, and a slightly earlier version of babel-core: 6.10.4

@VinceFanZ
Copy link

I've had the same problem.

@VinceFanZ
Copy link

user import { autobind } from 'core-decorators'

@smashercosmo
Copy link

gaearon/react-transform-catch-errors#26 probably related

@alexilyaev
Copy link

@VinceFanZ Did not work for me with core-decorators

@Jinnified
Copy link

@smashercosmo if my dependency's dependency has react-transform-catch-errors and i have transform-decorators-legacy, could this still causing issues?

@alexilyaev
Copy link

This might be related:
jayphelps/core-decorators#48 (comment)

@iamricky
Copy link

iamricky commented Dec 13, 2016

I'm still receiving the Uncaught TypeError: Cannot set property render of #<ComponentName> which has only a getter when binding to the class, e.g.

@autobind
class Component { }

Has this issue been addressed? Please advise.

source:
https://github.com/gaearon/react-transform-catch-errors/issues/26#issuecomment-197078851

@AndrewRayCode
Copy link
Author

I think this project is abandonware that will only work with older versions of something (babel? react?)

@stevemao
Copy link
Collaborator

See #29

@silent-tan
Copy link

met the same problem, anything else solution?

@smashercosmo
Copy link

I fixed it long time ago in react-transform-catch-errors gaearon/react-transform-catch-errors@afbbda8 It just wasn't published. Installing directly from master should work for everyone who faced this issue.

@stevemao
Copy link
Collaborator

stevemao commented Jul 1, 2017

98968ee should have fixed this. Please try the latest master branch :)

@stevemao stevemao closed this as completed Jul 1, 2017
@alexilyaev
Copy link

With react-hot-loader 3 this worked with version v1.4.1 as well.
Tested now with v2.1.0, still works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants