[英]“ERROR in loader Users/abc/node_modules/babel-core/index.js?{”presets“:[”react“]} didn't return a function ”
When I'm doing webpack I'm getting into this error: 当我在做webpack时,我陷入了这个错误:
ERROR in loader Users/abc/node_modules/babel-core/index.js?{"presets":["react"]} didn't return a function
webpack.config.js 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 的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 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'));
package structure : 包装结构:
app
|
|-src
|
|-main.js
|-index.html
|-webpack-config.js
in your webpack.config.js file make the loader be loader:babel-loader and it would work. 在您的webpack.config.js文件中,使加载程序为loader:babel-loader ,它将可以正常工作。 no need to uninstall
无需卸载
module:{
loaders:[
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.