I have had the same problem for a long time and I suspect this is a mistake. I have a workaround, remove the asp-prerender-webpack-config attribute from the tag, and configure webpack to output the file with the extension to another file with the same name. Make sure you add libraryTarget: 'commonjs2' to the webpack configuration file to make it work, since you need to export the load function as follows: module.exports . By default, webpack does not export anything, you must specify this yourself. Below are the codes needed to work, as this works for me:
clients.jsx
var React = require("react"); var ReactDOMServer = require("react-dom/server"); var Test = React.createClass({ render: function(){ return (<h1>Hello!</h1>); } }); module.exports = function (params) { return new Promise((resolve, reject) => { resolve({ html: ReactDOMServer.renderToString(<Test />) }); }); }
webpack.config.js
/// <binding ProjectOpened='Watch - Development' /> var webpack = require('webpack'); var path = require('path'); var MODULES = path.resolve(__dirname, "wwwroot/modules"); module.exports = { resolve: { extensions: ['', '.js', '.jsx'], modulesDirectories: ['node_modules'] }, entry: { clients: MODULES + "/clients.jsx" }, output: { path: MODULES, filename: "[name].js", libraryTarget: 'commonjs2' }, module: { loaders: [ { test: /\.jsx?/, include: MODULES, loader: 'babel-loader' } ] }, plugins: [], target: "node" };
Index.cshtml
<div id="clients" asp-prerender-module="wwwroot/modules/clients" asp-prerender-data="@Model" ></div>
.babelrc
{ "presets": [ "es2015", "react" ] }
packages.json
"devDependencies": { "aspnet-prerendering": "^1.0.7", "aspnet-webpack": "^1.0.17", "aspnet-webpack-react": "^1.0.2", "babel-core": "^6.17.0", "babel-loader": "^6.2.5", "babel-plugin-add-module-exports": "^0.2.1", "babel-preset-es2015": "^6.16.0", "babel-preset-react": "^6.16.0", "react": "^15.3.2", "react-dom": "^15.3.2", "webpack": "^1.13.2" }, "scripts": { "dev": "webpack -d --watch", "build": "webpack -p" }
Thus, the reaction components will be located in: ./wwwroot/modules and inside this folder will be both clients.jsx and clients.js .