I’m getting an error in my React app ** only after I build on my server. ** This error doesn’t happen on my local machine.
I’m getting an error that says: “Uncaught SyntaxError: Unexpected token ‘<‘ (at main.9ade8857.js:1:1)“
enter image description here
This is a simplified code example as this issue is impacting several other more serious apps:
//index.html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="theme-color" content="#000000" />
<title>React App</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
//index.js file:
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
//App.js file
import './App.css';
function App() {
return (
<div className="App">
<h1>Hosting Home Page</h1>
</div>
);
}
export default App;
I was expecting the build version on my server to work exactly like my dev version on my local machine. No changes were made. Just deployed the app.
Avik Ghosh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.