You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
Repository navigation
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
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.
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)
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:
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!
Activity
MarkPieszak commentedon Jan 31, 2017
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)
SteveSandersonMS commentedon Jan 31, 2017
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.jsfile, 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-spaYeoman generator (version 0.8.0), and create a new React-Redux app. You can rename theboot-server.tsxfile toboot-server.jsxif you want, and then edit its contents to be valid ES code (remove the<RenderResult>annotation on line 11, and the: anyannotation on line 13). Now changewebpack.config.jsso that the server-side entrypoint on line 59 isboot-server.jsx, and in the array ofrules(starting at line 19), add an entry telling it to use Babel for.js/.jsxfiles: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!