When trying to render my react application on the server, I'm receiving the following error:
Error: Uncaught error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Here is my server.js code, I've removed the server configuration for brevity.
import hapi from 'hapi';
import inert from 'inert';
import path from 'path';
import fs from 'fs';
import React from 'react';
import { ReactDOM, renderToString } from 'react-dom/server';
import { RouterContext, ReactRouter, match } from 'react-router';
import { Provider } from 'react-redux';
import routes from './src/config/routes';
import store from './src/flux/store';
...
match({routes, location: request.url.path}, function(err, redirectLocation, renderProps) {
if (err) {
reply(err.message).status(500);
} else if (redirectLocation) {
reply()
.redirect(redirectLocation.pathname + redirectLocation.search)
.code(302);
} else if (renderProps) {
var element = (
<RouterContext {...renderProps} />
);
console.log(element);
reply(renderToString(element)).code(200);
} else {
reply('Page Not Found')
}
});
The renderProps block of the if statement is getting called, and this is where the error is thrown.
EDIT: When I console.log RouterContext after my import from react-router, I'm getting undefined.
You can view my package.json for versions here: http://pastebin.com/mpb6XSKu