Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: serverRenderer is not a function

See original GitHub issue

I don’t get the error until I try to load the page:


import React from 'react';
import ReactDOMServer from 'react-dom/server';
import { match } from 'react-router/es6';
import { ServerRoot } from 'Root';
import configureStore from 'store';
import cheerio from 'cheerio';

module.exports = function(indexHTML) {
    return function (req, res) {
        var routes = require('./routes.jsx');
        var store = configureStore();

        var css = [];

            routes: routes.default,
            location: req.originalUrl
        }, (error, redirectLocation, renderProps) => {
            if (error) {
            } else if (redirectLocation) {
                res.redirect(302, redirectLocation.pathname +
            } else if (renderProps) {
                var body = ReactDOMServer.renderToString(
                    <ServerRoot store={store} renderProps={renderProps} onInsertCss={(...styles) => {
                        styles.forEach(style => css.push(style._getCss()));

                const state = store.getState();

                var $ = cheerio.load(indexHTML);

                $('#redux-state').html('window.__REDUX_STATE__ = ' + JSON.stringify(state).replace(/<\/script/g, '<\\/script').replace(/<!--/g, '<\\!--') + ';');
                $('#app').html('<div>' + body + '</div>');

                res.set('content-type', 'text/html');
            } else {
                res.status(404).send('Not found')


var webpack = require('webpack');
var clientConfig = require(path.join(__dirname, '/config/webpack.config.client.js'));
var serverConfig = require(path.join(__dirname, '/config/webpack.config.server.js'));
var devServerConfig = clientConfig.devServer;

app.use(serverConfig.output.publicPath, express.static(serverConfig.output.path));

app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public/favicons')));

if (process.env.NODE_ENV === 'development') {
    var compiler = webpack(clientConfig);

    var serverCompiler = webpack([clientConfig, serverConfig]);

    const webpackDevMiddlewareInstance = require('webpack-dev-middleware')(compiler, devServerConfig);
    const webpackHotServerMiddlewareInstance = require('webpack-hot-server-middleware')(serverCompiler);


    if ( {
        app.use(require('webpack-hot-middleware')(compiler, {
            log: console.log,
            path: '/__webpack_hmr',
            heartbeat: 10000

    webpackDevMiddlewareInstance.waitUntilValid(function () {
        compiler.outputFileSystem.readFile(path.join(compiler.outputPath, 'index.html'), function (err, result) {
            if (err) throw err;

} else
    ready(fs.readFileSync(path.join(__dirname, 'builds/client/index.html')));

function ready(indexHTML) {
    app.use('*', require('./builds/server/server.js')(indexHTML));

I may be doing something very wrong or incorrectly since I am still relatively new to all of this.


Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

eladocommented, Nov 30, 2017

about illegal operation on a directory error: if you have multi entry server, make sure to specify the chunkName:

entry: {
  index: './src/server.js',
app.use(webpackHotServerMiddleware(compiler, { chunkName: 'index' }));


emmanuel-mendozacommented, Apr 8, 2017

@richardscarrott I just tried your suggestion (these have been crazy days at work) and now it works like a charm, thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

serverRenderer is not a function · Issue #75 - GitHub
I had to set output: { libraryTarget: 'commonjs2' } in my server webpack config. All reactions.
Read more >
type error: server render is no a function - Stack Overflow
serverRender() doesn't return Promise . You can try to the callback based approach. const serverRender = (callback) ...
Read more >
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >
ReactDOMServer – React
This API has limited Suspense support and does not support streaming. On the server, it is recommended to use either renderToPipeableStream (for Node.js)...
Read more >
Server-side rendering (SSR) - Inertia.js
SSR is not yet ready for the Svelte adapter. However, it's something we're actively ... npm install @vue/server-renderer yarn add @vue/server-renderer.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found