I have created a React/Express server but when trying to import bootstrap I am getting the below:
Error
./node_modules/react-bootstrap/esm/Button.js
Module parse failed: Unexpected token (18:2)
You may need an appropriate loader to handle this file type.
| active,
| className,
| ...props
| }, ref) => {
| const prefix = useBootstrapPrefix(bsPrefix, 'btn');
Setup
App.js
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Customers from './components/customers';
import Button from 'react-bootstrap/Button';
import 'bootstrap/dist/css/bootstrap.min.css';
class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">React Express Starter</h1>
</header>
<Customers />
<div>
<div id="wallet-address"></div>
</div>
</div>
);
}
}
export default App;
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
I have webpack installed on both packages I am just completely lost as to why the issue is occurring. I have done the same without express with no issues but with both Express and React I can't seem to import any package without getting this same error.
Any help would be greatly appreciated.
A typical React/Express development setup looks like this, assuming the React app's development server is running on port 3000 and Express on 5000...
Proxy API requests for Express. In client/package.json add
"proxy": "http://localhost:5000",Launch your Express app however you prefer to launch it
Start your React app via npm start / yarn start in the app folder ( client in your case).
Open your browser at http://localhost:3000
When installing client-side libraries such as react-bootstrap, make sure to install them in the client/package.json file.
A production build looks more like this
Have Express statically serve files from your build directory and handle frontend paths
// make sure this comes after any routes, preferably last const path = requires("path"); const clientBuild = path.join(__dirname, "client", "build"); app.use(express.static(clientBuild)); app.get("/*", (_req, res) => { res.sendFile(path.join(clientBuild, "index.html")); }); Build your React app via npm run build / yarn build in the client folder.
Start your Express application however you prefer to start it
Open http://localhost:5000 in your browser.
Note that making changes to your React app in production mode requires a rebuild (step #2).