I am facing an issue while doing 'npm run build' my react application. Its saying as below:
Error below mentioned:
ERROR in ./src/index.js Module parse failed: Unexpected token (13:16) You may need an appropriate loader to handle this file type. | } | */ | ReactDOM.render(, document.getElementById('root')); @ multi ./src/index.js Child html-webpack-plugin for "index.html":
My Application consists of following Snippet and structure 1) webpack.config.js -
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var webpack = require('webpack');
var HTMLWebpackPluginConfig = new HtmlWebpackPlugin({
template: __dirname+'/src/index.html',
filename: 'index.html',
inject: 'body'
});
module.exports = {
entry:[
'./src/index.js'
],
module: {
rules: [{
test : /\.(js|jsx)$/,
include:__dirname+'/src/',
exclude: /node_modules/,
loader: 'babel',
query: {
cacheDirectory:true,
presets: ['es2015','react','stage-0']
}
}]
},
output: {
//path: path.resolve(__dirname, '/dist'),
filename: 'index_compiled.js',
path: __dirname+'/dist'
},
mode: 'none',
plugins: [HTMLWebpackPluginConfig]
};
2) ./src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import HelloWorld from './HelloWorld.jsx';
ReactDOM.render(<HelloWorld />, document.getElementById('root'));
3)./src/index.html**
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<title>React App</title>
</head>
<body>
<div id = "root"></div>
</body>
</html>
4)./src/HelloWorld.jsx
import {React,Component} from 'react';
class HelloWorld extends React.Component {
render() {
return(
<div>Hello World !!</div>
);
}
};
export default HelloWorld;
5) package.json
{
"name": "reacttuts",
"version": "1.0.0",
"description": "Creating React Apps V0.0.1",
"main": "index.js",
"scripts": {
"build": "webpack -p"
},
"author": "Ashwini kumar",
"license": "ISC",
"dependencies": {
"react": "^16.3.2",
"react-dom": "^16.3.2"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"coffee-loader": "^0.9.0",
"html-webpack-plugin": "^3.2.0",
"react-hot-loader": "^4.1.2",
"webpack": "^4.6.0",
"webpack-cli": "^2.0.15"
}
}