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
感謝它的工作:) – Tanveer