Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Call to Node module failed with error: If you use aspnet-prerendering >= 2.0.0, you must update your server-side boot module to call createServerRenderer. Either update your boot module code, or revert to aspnet-prerendering version 1.x #627

Closed

Description

@YuriiNskyi

The title of issue is self-descriptive.

My webpack.config:

var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var merge = require('extendify')({ isDeep: true, arrays: 'concat' });
var devConfig = require('./webpack.config.dev');
var prodConfig = require('./webpack.config.prod');
var isDevelopment = process.env.ASPNETCORE_ENVIRONMENT === 'Development';
var extractCSS = new ExtractTextPlugin('site.css');

module.exports = merge({
    resolve: {
        extensions: ['', '.js', '.jsx']
    },
    module: {
        loaders: [
            { test: /\.css/, loader: extractCSS.extract(['css']) },
            {
                loaders: ['react-hot', 'babel-loader'],
                include: [ path.resolve(__dirname), 'ClientApp' ],
                test: /\.js$/,
                plugins: ['transform-runtime']
            }
        ]
    },
    entry: { 'main-server': './ClientApp/boot-server.js' },
    output: {
        path: path.join(__dirname, 'wwwroot', 'dist'),
        filename: '[name].js',
        publicPath: '/dist/'
    },

    plugins: [
        extractCSS,
        new webpack.DllReferencePlugin({
            context: __dirname,
            manifest: require('./wwwroot/dist/vendor-manifest.json')
        })
    ]
}, isDevelopment ? devConfig : prodConfig);

My boot-server.js:

import * as React from 'react';
import { Provider } from 'react-redux';
import { renderToString } from 'react-dom/server';
import { match, RouterContext } from 'react-router';
import createMemoryHistory from 'history/lib/createMemoryHistory';
import { createServerRenderer } from 'aspnet-prerendering';
import routes from './routes';
import configureStore from './store/configureStore';

export default createServerRenderer(params => {
    return new Promise((resolve, reject) => {
        // Match the incoming request against the list of client-side routes
        match({ routes, location: params.location }, (error, redirectLocation, renderProps) => {
            if (error) {
                throw error;
            }

            // If there's a redirection, just send this information back to the host application
            if (redirectLocation) {
                resolve({ redirectUrl: redirectLocation.pathname });
                return;
            }

            // If it didn't match any route, renderProps will be undefined
            if (!renderProps) {
                throw new Error(`The location '${params.url}' doesn't match any route configured in react-router.`);
            }

            // Build an instance of the application
            const store = configureStore();
            const app = (
                <Provider store={store}>
                    <RouterContext {...renderProps} />
                </Provider>
            );

            // Perform an initial render that will cause any async tasks (e.g., data access) to begin
            renderToString(app);

            // Once the tasks are done, we can perform the final render
            // We also send the redux store state, so the client can continue execution where the server left off
            params.domainTasks.then(() => {
                resolve({
                    html: renderToString(app),
                    globals: { initialReduxState: store.getState() }
                });
            }, reject); // Also propagate any errors back into the host application
        });
    });
});

I've ran webpack command, dotnet restore also.

Then, when I'm trying to run project from VIsual Studio, it gives me error:

Call to Node module failed with error: If you use aspnet-prerendering >= 2.0.0, you must update your server-side boot module to call createServerRenderer. Either update your boot module code, or revert to aspnet-prerendering version 1.x

It doesn't depend whether I'm running project from Visual Studio or simply dotnet run from console.

What should I do? This guide isn't really helpful, because there is no difference between my solution and proposed.

Activity

  1. MarkPieszak commented on Jan 31, 2017

    @MarkPieszak
    Contributor

    You definitely have aspnet-Prerender 2.x installed in your package.json?
    What if you wipe out your node_modules and reinstall (assuming you have 2.x there)

  2. SteveSandersonMS commented on Jan 31, 2017

    @SteveSandersonMS
    Member

    I'm afraid I don't know why that's happening. I tried to set up a project in the same style (using your exact boot-server.js file, and amending my Webpack config to transpile it using babel), and it worked without trouble. I can't know why it's different in your case, because there are parts of your config you haven't posted (e.g., your .babelrc, and your other Webpack configs for dev/prod).

    A good way for you to figure out what's wrong in your case would be to compare your project against a working alternative. For example, get the latest generator-aspnetcore-spa Yeoman generator (version 0.8.0), and create a new React-Redux app. You can rename the boot-server.tsx file to boot-server.jsx if you want, and then edit its contents to be valid ES code (remove the <RenderResult> annotation on line 11, and the : any annotation on line 13). Now change webpack.config.js so that the server-side entrypoint on line 59 is boot-server.jsx, and in the array of rules (starting at line 19), add an entry telling it to use Babel for .js/.jsx files:

    { test: /\.jsx?$/, include: /ClientApp/, use: 'babel-loader' }
    

    That's what I tried when attempting to repro this, and it worked OK. Perhaps you could investigate to determine what's different in your app. Hope that helps!

    I'll close this because it doesn't appear to be a bug, but please let us know if you do discover that something's wrong with any of the code in this repo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions