Comments (10)
Both react-universal-component and webpack-hot-server-middleware can work with Webpack 4. However, this issue can get in the way:
webpack/webpack#7516
The "serverRenderer is not a function" error happens most often because the real error is swallowed on one of these two lines:
https://github.com/60frames/webpack-hot-server-middleware/blob/master/src/index.js#L152-L153
In the case of async code splitting - any code splitting, not just react-universal-component - that Webpack issue can leave you with a chunk name based off an async chunk rather than your entry point. So, with an entry name of "server" and an import()
of "Home" will sometimes cause LimitChunkCountPlugin to use the output + chunk name "Home" instead of "server," which leaves webapck-hot-server-middleware unable to find the default/configured chunk name + file of "server."
I'm attempting to put together a PR to provide friendly error reporting when something fails on these two lines. Took me the better part of an hour to figure out what was going on here.
from webpack-hot-server-middleware.
@jinxin479 you're going to have to provide a bit more information than that -- it's likely an issue with your configuration, see https://github.com/60frames/webpack-hot-server-middleware/search?q=serverRenderer+is+not+a+function&type=Issues
from webpack-hot-server-middleware.
sorry I found this error maybe caused by react-universal-component. this repo does not support webpack 4 so far.
from webpack-hot-server-middleware.
thank you ! I think I got it..
from webpack-hot-server-middleware.
i got the same issues
Environment
- node : "v10.9.0" - webpack: "^4.16.5" - webpack-hot-server-middleware: "^0.5.0"
My Repository
The code that i think caused this problem
server/index.js
const webpack = require('webpack')
const express = require('express')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const webpackHotServerMiddleware = require('webpack-hot-server-middleware')
const clientConfigDev = require('../webpack/client.dev')
const serverConfigDev = require('../webpack/server.dev')
const clientConfigProd = require('../webpack/client.prod')
const serverConfigProd = require('../webpack/server.prod')
const { publicPath } = clientConfigDev.output
const outputPath = clientConfigDev.output.path
const DEV = process.env.NODE_ENV === 'development'
const app = express()
let isBuilt = false
const done = () =>
!isBuilt &&
app.listen(3000, () => {
isBuilt = true
console.log('Build Complete')
})
if (DEV) {
const compiler = webpack([clientConfigDev, serverConfigDev])
const clientCompiler = compiler.compilers[0]
const options = { publicPath, stats: { color: true } }
const devMiddleware = webpackDevMiddleware(compiler, options)
app.use(devMiddleware)
app.use(webpackHotMiddleware(clientCompiler))
app.use(webpackHotServerMiddleware(compiler))
devMiddleware.waitUntilValid(done)
} else {
webpack([clientConfigProd, serverConfigProd]).run((err, stats) => {
const clientStats = stats.toJson().children[0]
const serverRender = require('../build/server.js').default
app.use(publicPath, express.static(outputPath))
app.use(serverRender({ clientStats }))
done()
})
}
i have an issue with the development mode when i open my app in browser, it said serverRenderer is not a function, everything is okay with production mode
from webpack-hot-server-middleware.
I had to set output: { libraryTarget: 'commonjs2' }
in my server webpack config.
from webpack-hot-server-middleware.
Started having the same error after upgrade to webpack 4. And I don't even have async chunks.
Update: solved it by using { serverSideRender: true } option for webpack-dev-middleware
from webpack-hot-server-middleware.
@nemixe did you solve your issue?
from webpack-hot-server-middleware.
None of the above solved this error when dealing with router AFTER whsm and BEFORE app listen (express).
webpack-contrib/webpack-hot-middleware#26 (comment)
this is where you can get error. changed order to router -> wdm config -> app listen
and got this:
localhost/:1 EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection.
so now the flow has to be wdm -> whm -> router -> whsm -> app listen
but event then its kinda working but it is not.
SSR works client renders but the error still present
serverRenderer is not a function
from webpack-hot-server-middleware.
in the webpack config for the server your entry point should be string:
entry: "./src/server/render.js",
You should change output.filename if your are using [name] computed property.
from webpack-hot-server-middleware.
Related Issues (20)
- Side effect from require server render from string
- listen EADDRINUSE: address already in use :::8080 HOT 2
- please remove `yarn` from dependencies HOT 4
- TypeError: serverRenderer is not a function
- Hangs when errors are thrown inside server bundle HOT 1
- filtering websocket webpack-hot-reloading calls from react-hot-server-middleware HOT 1
- serverRenderer is not a function HOT 1
- My entry chunk is renamed to an async chunk HOT 2
- is it possible to call the default route from another route in express HOT 5
- serverRender is not a function
- use webpack-hot-server-middleware with typescript HOT 2
- Another "serverRenderer is not a function" question. HOT 4
- React Redux store not found in context HOT 4
- cannot find module 'react'
- Why is yarn in runtime dependencies? HOT 1
- Separating Routes? HOT 6
- Error is thrown when the example is run.
- Error when compiling when using Hapijs HOT 1
- bug flow type HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpack-hot-server-middleware.