Skip to content

TypeError: serverRenderer is not a function #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arnoldjos opened this issue Jul 13, 2018 · 8 comments
Closed

TypeError: serverRenderer is not a function #132

arnoldjos opened this issue Jul 13, 2018 · 8 comments

Comments

@arnoldjos
Copy link

When i set webpack.optimize.LimitChunkCountPlugin maxChunks to 1 my entry bundle is renamed to my universal-component chunkname and shows this error.

TypeError: serverRenderer is not a function at D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\webpack-hot-server-middleware\src\index.js:13:5 at D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\webpack-hot-server-middleware\src\index.js:175:61 at Layer.handle [as handle_request] (D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\express\lib\router\index.js:317:13) at D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\express\lib\router\index.js:284:7 at Function.process_params (D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\express\lib\router\index.js:335:12) at next (D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\express\lib\router\index.js:275:10) at middleware (D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\webpack-hot-middleware\middleware.js:33:48) at Layer.handle [as handle_request] (D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\express\lib\router\index.js:317:13) at D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\express\lib\router\index.js:284:7 at Function.process_params (D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\express\lib\router\index.js:335:12) at next (D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\express\lib\router\index.js:275:10) at goNext (D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\webpack-dev-middleware\lib\middleware.js:16:16) at processRequest (D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\webpack-dev-middleware\lib\middleware.js:63:26) at ready (D:\MyProjects\Apps\Webpack-Course\MyBoilerplate\node_modules\webpack-dev-middleware\lib\util.js:52:12)

specs:
"webpack-dev-middleware": "^3.1.3",
"webpack-hot-middleware": "^2.22.2",
"webpack-hot-server-middleware": "^0.5.0",
"babel-plugin-universal-import": "^3.0.0",
"react-universal-component": "^2.9.0",
"webpack": "^4.16.0"

@ScriptedAlchemy
Copy link
Collaborator

Ahh I have seen this happen, I'm still not sure why it does this. There is a workaround though.

Let me test a few it out quickly

@ScriptedAlchemy
Copy link
Collaborator

Try creating a universalComponent file like this. There's an issue when universal tries to import itself.

The easy solution is to place the import in a utility file outside the directory you plan on importing

https://github.com/faceyspacey/universal-demo/tree/webpack-4/src

@threehams
Copy link
Contributor

threehams commented Jul 21, 2018

It's very likely an issue with webpack:
webpack/webpack#7516

webpack-hot-server-middleware expects a "main" chunk, but Webpack renames the chunk somewhat randomly when using LimitChunkCountPlugin. I have a PR to improve the error message for webpack-hot-server-middleware:
60frames/webpack-hot-server-middleware#75

This doesn't fix the issue, but it makes it more clear what's happening.

I have some work locally to infer the chunk name when there's only a single chunk, which would work around the Webpack issue. This would also rely on getting a PR merged into webpack-hot-server-middleware, though.

@ScriptedAlchemy
Copy link
Collaborator

I know a guy close to HOT stuff so I’ll ask him if he has an idea. In the meantime, just move the universal utility file up one directory so it doesn’t import it’s self. Check how I do it on the universal demo

@sharmam1
Copy link

@ScriptedAlchemy getting the same issue, even i kept my universal import outside of component directory

@threehams
Copy link
Contributor

I linked to the Webpack bug above that causes this, but last night someone went further and tracked it down to the code which decides which chunk name wins when merging chunks:
webpack/webpack#7516 (comment)

The shortest chunk name wins. If they're the same length, then whatever chunk name wins a > comparison becomes the new name. This was done as part of an 8,000 line commit and wasn't called out in the commit message, so it was likely just chosen arbitrarily (webpack/webpack@18ae73d). This explains why this seems to pop up randomly for some people and not others. I didn't see it until I added a split point at a Home component.

A workaround is to use an entry point name short enough that it always wins in this comparison.

On dev server:

app.use(webpackHotServerMiddleware(compiler, { chunkName: "m" }));

Webpack server config:

// old
{
  entry: [entry],
}

// new
{
  entry: {
    m: [entry],
  },
}

@ScriptedAlchemy
Copy link
Collaborator

@threehams thanks, this really was helpful!

@garrettmac
Copy link

garrettmac commented Jul 26, 2019

im on the latest and just ran into this issue with these change, it must be my config with how im using webpack-dev-server. I just need to wait a bit and refresh when starting up my server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants