Search code examples
reactjsfluxreactjs-flux

Error: Cannot find module 'react/lib/Object.assign' from dispatcher


Below is my dispatcher code

var Dispatcher = require("flux").Dispatcher;
var assign = require("react/lib/Object.assign");

var AppDispatcher = assign(new Dispatcher(), {
    handleViewAction: function(action){
        console.log('action', action)
        this.dispatch({
            source: 'VIEW_ACTION',
            action: action
        })
    }
});

module.exports = AppDispatcher;

gulp is not starting it is throwing error

Error: Cannot find module 'react/lib/Object.assign' from '/Users/shanky-munjal/projects/testFlux/src/js/dispatchers'
    at /Users/shanky-munjal/projects/testFlux/node_modules/browserify/node_modules/resolve/lib/async.js:46:17
    at process (/Users/shanky-munjal/projects/testFlux/node_modules/browserify/node_modules/resolve/lib/async.js:173:43)
    at ondir (/Users/shanky-munjal/projects/testFlux/node_modules/browserify/node_modules/resolve/lib/async.js:188:17)
    at load (/Users/shanky-munjal/projects/testFlux/node_modules/browserify/node_modules/resolve/lib/async.js:69:43)
    at onex (/Users/shanky-munjal/projects/testFlux/node_modules/browserify/node_modules/resolve/lib/async.js:92:31)
    at /Users/shankymunjal/projects/testFlux/node_modules/browserify/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:82:15)

I am using react 15.2.1


Solution

  • use Object.assign


    A long time ago Dan Abramov wrote:

    This is a gentle reminder that require('react/lib/SomeInternalModule') in your component will break in some release regardless of semver.