Currently, I am in the process of creating a boilerplate for React web applications.
However, whenever I try to access http://localhost:8080/, I encounter an error stating: Uncaught SyntaxError: Unexpected token <
in my bundle.js file.
I'm unsure of what steps to take next and would greatly appreciate any guidance or assistance.
Below are some of the key files involved:
/public/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>New app</title>
<link rel="stylesheet" href="/style.css" />
<script src="./bundle.js" defer> .</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
/client/app.js
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<div>Hello, world!</div>,
document.getElementById('app')
);
webpack.config.js
module.exports = {
entry: [
'@babel/polyfill', // enables async-await
'./client/app.js',
],
mode: 'development',
output: {
path: __dirname,
filename: `./public/bundle.js`,
},
devtool: 'source-maps',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
],
},
};
package.json
{
"name": "boilerplatelivmarx",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server",
"start-dev": "webpack -w & nodemon server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-preset-env": "^1.7.0",
"babel-preset-stage-2": "^6.24.1",
"express": "^4.16.4",
"path": "^0.12.7",
"react": "^16.6.0",
"react-dom": "^16.6.0",
"react-router-dom": "^4.3.1"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-react": "^6.24.1",
"webpack": "^4.23.1",
"webpack-cli": "^3.1.2"
}
}
Your help is really appreciated!