While trying to get react-router working on my Node/Express backend, React frontend I encounter this warning whilst trying to build
React.createElement: type is invalid -- expected a string
In search of answers I have discovered this already asked question
React.createElement: type is invalid -- expected a string
Of which the solutions involving * checking all my export default class Components... * Importing BrowserRouter from react-router-dom vs react-router
Do not correct my problem. Furthermore when I open DevTools in Chrome I see that the page is blank, React has not populated my root div and on top of all that There is a error in console client-bundle.js:1 Uncaught SyntaxError: Unexpected token <
When I click on this error, it leads me to the source for my client-bundle.js which does not contain javascript but the markup of the boilerplate html
I have been reading through examples, tutorials and documentations but have yet to find the source of my errors. I am hoping that someone here might see something I don't
umleto.js
import express from 'express';
import router from './routing/router';
// Basic config
const PORT = 3000;
const HOST = 'localhost';
const app = express();
// Setup server side router
router(app);
// Setup EJS template engine
app.set('views', `${__dirname}/views`);
app.set('view engine', 'ejs');
// Start server
const server = app.listen(PORT, () => console.log(`Listening to ${HOST}:${PORT}`));
routing/router.js
import React from 'react';
import { renderToString } from 'react-dom/server';
import { StaticRouter } from 'react-router';
import Routes from './Routes';
import NotFoundPage from '../frontend/components/NotFoundPage';
// React Router as middleware
const router = (req, res, next) => {
const context = { routes: Routes, location: req.url };
const markup = renderToString( <StaticRouter context={context} /> );
res.render('index', { markup });
next();
}
export default (app) => app.use(router);
routing/Routes.jsx
import React from 'react';
import { Route, IndexRoute, Switch } from 'react-router';
import Layout from '../frontend/components/Layout';
import NotFoundPage from '../frontend/components/NotFoundPage';
import IndexPage from '../frontend/components/IndexPage';
// Client Side Routing
const Routes = (
<Route path="/" component={Layout}>
<IndexRoute component={IndexPage}/>
<Route path="*" component={NotFoundPage}/>
</Route>
);
export default Routes;
I have a git hub repository setup incase anyone wants a better look at my problem code. https://github.com/slipsnip/UMLeto