2017-01-09 33 views
1

我正在ReactJs中编写一个应用程序。我使用webpack。当我试着开始我的应用程序,我有一些奇怪的例外,我不能在这个时候解释:通过在ReactJs中编写一些应用程序的奇怪例外

ERROR in ./src/index.js 
    Module build failed: TypeError: Cannot read property 'cacheable' of undefined 
    at module.exports (/Users/rogozindaniil/Documents/sc-react-redux/node_modules/react-hot-loader/index.js:9:11) 
    at Function.memoisePluginContainer (/Users/rogozindaniil/Documents/sc-react-redux/node_modules/babel-core/lib/transformation/file/options/option-manager.js:109:13) 
    at Function.normalisePlugin (/Users/rogozindaniil/Documents/sc-react-redux/node_modules/babel-core/lib/transformation/file/options/option-manager.js:142:32) 
    at /Users/rogozindaniil/Documents/sc-react-redux/node_modules/babel-core/lib/transformation/file/options/option-manager.js:180:30 
    at Array.map (native) 
    at Function.normalisePlugins (/Users/rogozindaniil/Documents/sc-react-redux/node_modules/babel-core/lib/transformation/file/options/option-manager.js:154:20) 
    at OptionManager.mergeOptions (/Users/rogozindaniil/Documents/sc-react-redux/node_modules/babel-core/lib/transformation/file/options/option-manager.js:229:36) 
    at OptionManager.init (/Users/rogozindaniil/Documents/sc-react-redux/node_modules/babel-core/lib/transformation/file/options/option-manager.js:374:12) 
    at File.initOptions (/Users/rogozindaniil/Documents/sc-react-redux/node_modules/babel-core/lib/transformation/file/index.js:216:65) 
    at new File (/Users/rogozindaniil/Documents/sc-react-redux/node_modules/babel-core/lib/transformation/file/index.js:139:24) 

@多主

+0

附上您的package.json,也许你index.js了。只有这个错误才能帮助你。谢谢。 –

+0

尝试安装3.0.0或更高版本的react-hot-roader –

回答

0

这是非常困难没有更多的源代码说提出,但我想象你忘记使用new当你添加hot-loader模块。它应该是:

plugins: [ 
    new webpack.HotModuleReplacementPlugin() 
] 

假设你的错误是从这里来的:https://github.com/gaearon/react-hot-loader/blob/master/index.js#L9-L11,我能想到的是thisundefined的唯一方法是,如果你没有通过不使用new

0

给它适当的范围内当然是。还有我的index.js文件:

import React from 'react'; 
import ReactDOM from 'react-dom'; 
import Stream from './components/Stream'; 

const tracks = [ 
    { 
    title: 'Track 1' 
    }, 
    { 
    title: 'Track' 
    } 
]; 

ReactDOM.render(
    <Stream tracks={tracks} />, 
    document.getElementById('app') 
); 

而且还有的package.json

{ 
    "name": "Soundcloud-React", 
    "version": "1.0.0", 
    "description": "", 
    "main": "index.js", 
    "scripts": { 
    "start": "webpack-dev-server --progress --colors --hot --config ./webpack.config.js", 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "keywords": [], 
    "author": "", 
    "license": "ISC", 
    "babel": { 
    "presets": [ 
     "es2016", 
     "react", 
     "stage-2" 
    ], 
    "plugins": [ 
    "react-hot-loader", 
    "babel"] 
    }, 
    "devDependencies": { 
    "babel-core": "^6.21.0", 
    "babel-loader": "^6.2.10", 
    "babel-preset-es2016": "^6.16.0", 
    "babel-preset-react": "^6.16.0", 
    "babel-preset-stage-2": "^6.18.0", 
    "react-hot-loader": "^1.3.1", 
    "webpack": "^1.14.0", 
    "webpack-dev-server": "^1.16.2" 
    }, 
    "dependencies": { 
    "react": "^15.4.2", 
    "react-dom": "^15.4.2" 
    } 
}