2016-10-04 31 views
1

當我在做webpack時,這個錯誤:「加載器用戶中的錯誤/ abc/node_modules/babel-core/index.js?{」presets「:[」react「]}沒有返回函數」

ERROR in loader Users/abc/node_modules/babel-core/index.js?{"presets":["react"]} didn't return a function 

webpack.config.js

module.exports = { 
    entry: './src/main.js', 
    output: { 
    filename: 'bundle.js', 
    path: __dirname + '/dist' 
    }, 
    module: {`enter code here` 
    loaders: [ 
     { 
     test: /\.jsx?$/, 
     exclude: /(node_modules|bower_components)/, 
     loader: 'babel-core', 
     query: { 
       presets: ['react'] 
      } 
     } 
    ] 
    } 
}; 

的index.html

<html> 
    <head> 
     <title>React JSX (Precompiled) demo</title> 
    </head> 
    <body> 
     <div id="mycontainer"></div> 
     <script src="./dist/bundle.js"></script> 
    </body> 
</html> 

main.js

var React = require('react'); 
var ReactDOM = require('react-dom'); 

var ReactComponent = React.createClass({ 
    render : function(){ 
    return( <div> 
    <h1>Welcome to React Js! </h1> 
    </div> 
); 
    } 
}); 

ReactDOM.render(<ReactComponent/>,document.getElementById('mycontainer')); 

封裝結構:

app 
    | 
    |-src 
    | 
    |-main.js 
    |-index.html 
    |-webpack-config.js 

回答

3

babel-core是通天的核心,它不是一個加載器。您應該使用:

loader: 'babel-loader' // Or just 'babel' 

見例如here

不要忘記使用NPM安裝通天裝載機。

希望這有助於

+0

感謝它的工作:) – Tanveer

0

webpack.config.js文件使裝載機裝載機:巴貝爾裝載機和它的工作。無需卸載

module:{ 
    loaders:[ 
     { 
      test: /\.jsx?$/, 
      loader: 'babel-loader', 
      exclude: /node_modules/ 
     } 
    ] 
}