2017-01-09 32 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" 
    } 
}