I'm just learning React from the scratch and while following the course I've reached the problem with starting the app by npm run dev:server command. The console log returns:
SyntaxError: C:/Users/woj/Desktop/moje/react env/src/server/server.js: Unexpected token (10:54)
8 |
9 | server.get("/", (req, res) => {
> 10 | const initialMarkup = ReactDOMServer.renderToString(<App />);
| ^
11 |
12 | res.send(`
13 | <html>
It's related with babel parser. Anyone can try to help me? Thanks from the advance.
server.js
import express from "express";
import React from "react";
import ReactDOMServer from "react-dom/server";
import App from "../components/App";
const server = express();
server.use(express.static("dist"));
server.get("/", (req, res) => {
const initialMarkup = ReactDOMServer.renderToString(<App />);
res.send(`
<html>
<head>
<title>Sample React App</title>
</head>
<body>
<div id="mountNode">${initialMarkup}</div>
<script src="/main.js"></script>
</body>
</html>
`);
});
server.listen(4242, () => console.log("Server is running..."));