Skip to main content

Hi All,

I have a problem with my project with React.

I get the following error:


This is my App.js in the Server folder:

require(‘dotenv’).config();


//require(“@babel/register”)({ presets: r“@babel/preset-react”, “@babel/preset-env”]});


const path = require(‘path’);


const express = require(‘express’);


const bodyParser = require(‘body-parser’);


const routes = require(‘./routes/index’);


const itemViewRoutes = require(‘./routes/itemView’);


const { PORT: port } = process.env;


const app = express();


app.use(bodyParser.json());


app.use(routes);


app.use(‘/api/itemView’, itemViewRoutes);


app.use(express.static(path.join(__dirname, ‘public’)));


app.listen(port, () => {


console.log(Server listening on port ${port});


});


// Serve static files from the ‘public’ directory


app.use(express.static(path.join(__dirname, ‘…’, ‘client’, ‘public’)));


app.use(express.static(path.join(__dirname, ‘…’, ‘client’, ‘src’)));


app.use(express.static(path.join(__dirname, ‘…’, ‘client’, ‘node_modules’)));


app.use(express.static(path.join(__dirname, ‘…’, ‘client’)));


//Error handling


app.use((error, req, res, next) => {


if (res.headerSent) {


return next(error);


}


res.status(error.code || 500);


res.json({ message: error.message || ‘Priority - An unknown error occurred’ });


});


module.exports = app;


This is my App.js in the Client folder:

import React from “react”;


const App = () => {

return

A react app

;

};

export default App;


This is my Index.html in the Client folder:












<title>React App</title>



<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

<h1>Welcome to My Express Server</h1>
<script type="module" src="/App.js"> </script>
Be the first to reply!

Reply