错误:无法从调度程序中找到模块'react / lib / Object.assign'

时间:2016-07-21 12:55:57

标签: reactjs flux reactjs-flux

以下是我的调度员代码

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没有启动它正在抛出错误

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)

我正在使用react 15.2.1

2 个答案:

答案 0 :(得分:0)

使用Object.assign

很久以前 Dan Abramov wrote

  

这是一个温和的提醒,需要(' react / lib / SomeInternalModule')   无论semver如何,你的组件都会在某个版本中中断。

答案 1 :(得分:0)

 npm install object-assign --save

此代码将起作用

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

此代码代替

 var assign = require("Object-assign");