react-hot-loader: "Can't make class hot reloadable due to being read-only”
I’m getting the "Can’t make class hot reloadable due to being read-only” warning on three of my components. Considering that these are ordinary components, I am a bit confused by this error; it seems random. Any ideas what could have gone wrong?
Here is an example of one such component that is throwing the error. The other two components are reasonably similar to this one:
import React, { Component } from 'react';
import { View } from 'components/layout';
import { RegisterForm } from './components';
const viewConfig = {
...
};
export default class RegisterView extends Component {
render() {
return (
<View {...viewConfig}>
<RegisterForm />
</View>
);
}
}
EDIT:
Looks like this is connected to #72?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 34 (10 by maintainers)
Links to this issue
Commits related to this issue
- Fix hot reload warning https://github.com/gaearon/react-hot-loader/issues/158 — committed to msembinelli/redux-in-docker-boilerplate by msembinelli 7 years ago
I too was getting this issue. After reading comments above i fixed it by doing following thing
Useful link - https://medium.com/@kentcdodds/misunderstanding-es6-modules-upgrading-babel-tears-and-a-solution-ad2d5ab93ce0#.rvrx62s5p
And FYI the links in the warning are incorrect: http://babeljs.io/docs/advanced/loose/ is 404 http://babeljs.io/docs/usage/options/ doesn’t mention
loosemodeAfter a lot of head-banging, we replaced
with
and that seems to be working for us.
Remove warnings:
I was also experiencing this. The warning goes away when I stop using an index file to reexport things in bulk.
tl;dr:
export {default as FooComponent} from './FooComponent'is what breaks things.Setup
Given a filesystem like so:
with client/components/index.js:
With webpack’s
resolve.rootpointing atclient/, I’d import components elsewhere like soAnd get the warning about Spinner being readonly.
The fix
Alter client/component/index.js to export things like so:
Edit: no circular imports
This approach works okay but you can’t do the following inside a component:
Instead, load the desired component directly:
Have tried all the solutions in this thread, nothing works to remove the warning. However, hot reloading is working as expected for the relevant components.
Another solution is
Instead of having to update both
importandexportsections, each component has one line.@gaearon - curious, is
3.0going to solve that?I ran into this issue, and it’s happening in a super confusing way. When I created a
Mainfile to centralize all my exports for a particular widget, I did this:(
ReduxQueryEditor, in this case, being the result ofReact.createClassand everything else being either a function or an object)The warning I got wasn’t on any of the
default as blahstuff I was exporting. I got the warning onReduxQueryEditor.I was able to fix it like this:
This is really confusing though. I’m exporting defaults from other modules, not from that one.