score:18

Accepted answer

Looks like you and I were in the same boat. We were both using an old version of react-hot-loader update to version 3.x and do another npm install.

see - https://github.com/gaearon/react-hot-loader/issues/417

score:-1

Go to node_modules/react-hot-loader/index.js and use try catch instead of required

replace this code

prependText = [
'/* REACT HOT LOADER */',
'if (module.hot) {',
  '(function () {',
    'var ReactHotAPI = require(' + JSON.stringify(require.resolve('react-hot-api')) + '),',
        'RootInstanceProvider = require(' + JSON.stringify(require.resolve('./RootInstanceProvider')) + '),',
        'ReactMount = require("react/lib/ReactMount"),',
        'React = require("react");',

    'module.makeHot = module.hot.data ? module.hot.data.makeHot : ReactHotAPI(function () {',
      'return RootInstanceProvider.getRootInstances(ReactMount);',
    '}, React);',
  '})();',
'}',
'try {',
  '(function () {',
 ].join(' ');

to new code using try and catch to handle error

var reactMountImport;
   try {
 require('react-dom/lib/ReactMount');
     reactMountImport = 'ReactMount = require("react-dom/lib/ReactMount"),';
  } catch(e) {
   console.log(e)
  reactMountImport = 'ReactMount = require("react/lib/ReactMount"),';
  }

 prependText = [
'/* REACT HOT LOADER */',
'if (module.hot) {',
  '(function () {',
    'var ReactHotAPI = require(' + JSON.stringify(require.resolve('react-hot-api')) + '),',
        'RootInstanceProvider = require(' + JSON.stringify(require.resolve('./RootInstanceProvider')) + '),',
        reactMountImport,
        'React = require("react");',

    'module.makeHot = module.hot.data ? module.hot.data.makeHot : ReactHotAPI(function () {',
      'return RootInstanceProvider.getRootInstances(ReactMount);',
    '}, React);',
  '})();',
'}',
'try {',
  '(function () {',
].join(' ');

you can check changes here https://github.com/gaearon/react-hot-loader/pull/430/commits/4ff08252bd8bf90dbc89fc6d032f557825ec0300#diff-168726dbe96b3ce427e7fedce31bb0bc

score:0

What worked for me was to simple change from react: ^15.0.0 to 15.3.1.

score:0

You would need to update react in order to resolve this. In my case, I wasn't using hot loader. An upgrade to react resolved this. Currently on 15.4.0


Related Query

More Query from same tag