serve does not work with multi-server #2408
Description
Describe the bug
We're having issues updating to webpack 5 and webpack serve. Our project is divided into multiple webpack configurations. Say for example we have one configuration for a SPA /login/ , /portal/, our application for end users and /admin/ for our administrators. We do this, so that every SPA when hosted belongs into its own folder and we can easily make sure that critical code like in our /admin/ SPA is never served outside of intranet. Now to test locally, we use webpack-dev-server's multi project configuration. Every SPA is identifiable by an unique publicPath (e. g. /admin). This worked beautifully with webpack-dev-server, but with webpack 5 and webpack-cli this is no longer the case. We use multiple webpack configurations to test our
We used to use webpack-dev-server to start our development server directly, however as I understand that is no longer working with webpack 5.
What is the current behavior?
Webpack-cli outputs a an error message:
Error: Unique ports must be specified for each devServer option inyour webpack configuration. Alternatively, run only 1 devServer config using the--config-name flag to specify your desired config.
at Object.startDevServer [as default]
To Reproduce
Steps to reproduce the behavior:
https://github.com/webpack/webpack-cli/blob/master/test/serve/basic/multi-dev-server.config.js without the explicit ports does show my use case perfectly.
Expected behavior
If publicPaths for configurations are unique, webpack serve should be able to serve them from the same port.
Screenshots
Please paste the results of webpack-cli info here, and mention other relevant information
Additional context
Maybe this was first introduced with #1649 A possible solution might be to change
| export default function startDevServer(compiler, devServerArgs): object[] { |
publicPaths if ports are not unique.
Thanks a lot,
Christian
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
alexander-akait commentedon Feb 4, 2021
yep, because it is impossible, each compiler should have unique port, it is limitation, you can use multi entry syntax:
Even more - I don't think it is real can be solved, we don't know your files after compilation, and
filenameandpublicPathand other can be functions so we even predict it.Christian24 commentedon Feb 5, 2021
Well, multiple entries wouldn't work in our case, since that wouldn't allow us to specify the correct
publicPathper entry, right?I am a bit confused why this no longer works, since this worked just fine in webpack@4 and I am honestly a bit uncertain as to what our upgrade path can be.
alexander-akait commentedon Feb 5, 2021
@Christian24 Can you provide example with webpack@4? I want to look at this, maybe be I am don't understand you correctly
Christian24 commentedon Feb 5, 2021
@alexander-akait sure. https://github.com/Christian24/webpack-dev-server-multi-config/tree/main This should give you a very basic example of what we are doing with webpack4 at the moment, but I am unable to recreate using webpack5. If you need additional details, please let me know.
alexander-akait commentedon Feb 6, 2021
@Christian24 hm, works fine with webpack v5 and webpack-cli v4, my command is
webpack serve --config ./webpack.config.js, when you set twodevServeoptions, it means you need two dev servers, but in you case you don't need italexander-akait commentedon Feb 6, 2021
Here some architecture limitations, because
webpack-dev-servershould be plugin, and you can apply it for all configurations and for the each configuration, it is on roadmap for webpack-dev-server v4, right now if you need to set port please usewebpack serve --config ./path/to/webpack.config.js --port 8081And here your case - you need apply webpack-dev-server on multi compiler level and set the
portoption. Right now you can setportusing thedevServeroption for first compiler.In future we will fix this limitation
Christian24 commentedon Feb 6, 2021
First of all thank you, @alexander-akait! You are very right that my example works fine with webpack5, I just checked. However, you were also correct that the multiple
devServerconfigurations cause my issue. I always thought they would apply per configuration and not globally.To everyone running into the same issue I have adapted my initial example into a
Is it just me or is the the multi-compiler feature lacking documentation? I would be happy to help if hands are needed with that, since it is an invaluable feature for me.
Christian24 commentedon Feb 6, 2021
I do not want to reinvent the wheel, but wouldn't a syntax like
{ devServer: ..., configurations: [...] }be nicer since it would make make more explicit what part of the configuration is shared globally?
alexander-akait commentedon Feb 6, 2021
@Christian24 Yep, I think it should be like this, but changing syntax in config files will be a big problem, I need think about it
alexander-akait commentedon Feb 6, 2021
Let's keep open, I want to search right way for this or update docs with the limitation (official)
24 remaining items
evenstensberg commentedon Jul 9, 2024
@alexander-akait any update on this?
alexander-akait commentedon Jul 10, 2024
No, we need implement plugin support for devserver
ImStillBlessed commentedon Mar 11, 2026
Hi! @alexander-akait @evenstensberg I'm interested in GSoC '26 and would like to work on this as my qualifying contribution. Is this still open for a PR?