1

Have a react app using react router with node/express server on the backend, I'm trying to deploy to heroku, but it is giving me this error...

'Uncaught SyntaxError: Unexpected token <'

I believe it is my 'catch all' route in my express server which is serving up index.html.. not exactly sure... Here is a bit of my server file..

const express = require('express');
const bodyParser = require('body-parser');

const app = express();
const path = require('path');
const bcrypt = require('bcrypt');
const db = require('../database/index.js');
const passport = require('passport');
const helpers = require('./helpers.js');//eslint-disable-line
require('../server/config/passport')(passport);

app.use(express.static(path.join(__dirname, '/../client/dist')));
app.use(require('cookie-parser')());
app.use(require('body-parser').urlencoded({ extended: true }));
app.use(require('express-session')({
  secret: process.env.SESSION_PASSWORD || 'supersecretsecret',
  resave: false,
  saveUninitialized: false,
}));

app.use(passport.initialize());
app.use(passport.session());
app.use(bodyParser.json());

app.post('/', (req, res) => {
  res.end();
});

app.get('/*', (req, res) => {
  res.sendFile(path.join(__dirname, '/../client/dist/index.html'));
});

app.listen(process.env.PORT || 3000, () => {
  console.log('listening on port 3000!');
});

Here is my index.jsx file for the front end..

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import Home from './components/homepage.jsx';
import ArtistRegister from './components/artistregister.jsx';
import VenueRegister from './components/venueregister.jsx';
//import Test from './components/test.jsx';
import reducer from './reducers/index.js';
import { BrowserRouter as Router, Route, Switch } from 'react-router- 
dom';//eslint-disable-line

const store = createStore(reducer, applyMiddleware(thunk));

const Base = ({ store }) => (
  <Provider store={store}>
    <Router>
      <Switch>
        <Route exact path="/" component={Home} />
        <Route exact path="/artistregister" component={ArtistRegister} 
        />
        <Route exact path="/venueregister" component={VenueRegister} />
        {/* <Route path="/artist/:username" component={Test} /> */}
      </Switch>
    </Router>
  </Provider>
);

const render = () => {
  ReactDOM.render(<Base store={store} />, 
  document.getElementById('app'));
  };

store.subscribe(render);
render();

any help?

3
  • You need to transpile the JSX into Javascript, either before you push to the server or, have a a postinstall script that runs the build. Commented Mar 27, 2018 at 22:51
  • Ok i will look into that, but is there a reason why this wouldn't work on heroku when it is locally?? Commented Mar 27, 2018 at 22:58
  • because I have never had this issue before, I assumed the jsx was automatically transpiled with webpack. Commented Mar 27, 2018 at 22:59

1 Answer 1

1

I figured it out! it was transpiling correctly using babel, the only issue was that when deploying, my bundle.js was in the git-ignore.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.