Skip to content

serve does not work with multi-server #2408

Open

Description

@Christian24

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[] {
to add an additional check for unique publicPaths if ports are not unique.

Thanks a lot,
Christian

Activity

  1. alexander-akait commented on Feb 4, 2021

    @alexander-akait
    Member

    yep, because it is impossible, each compiler should have unique port, it is limitation, you can use multi entry syntax:

    {
      entry: {
        pageOne: './src/page-one.js',
        pageTwo: './src/page-two.js'
      }
    }
    

    Even more - I don't think it is real can be solved, we don't know your files after compilation, and filename and publicPath and other can be functions so we even predict it.

  2. Christian24 commented on Feb 5, 2021

    @Christian24
    Author

    Well, multiple entries wouldn't work in our case, since that wouldn't allow us to specify the correct publicPath per 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.

  3. alexander-akait commented on Feb 5, 2021

    @alexander-akait
    Member

    @Christian24 Can you provide example with webpack@4? I want to look at this, maybe be I am don't understand you correctly

  4. Christian24 commented on Feb 5, 2021

    @Christian24
    Author

    @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.

  5. alexander-akait commented on Feb 6, 2021

    @alexander-akait
    Member

    @Christian24 hm, works fine with webpack v5 and webpack-cli v4, my command is webpack serve --config ./webpack.config.js, when you set two devServe options, it means you need two dev servers, but in you case you don't need it

  6. alexander-akait commented on Feb 6, 2021

    @alexander-akait
    Member

    Here some architecture limitations, because webpack-dev-server should 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 use webpack serve --config ./path/to/webpack.config.js --port 8081

    And here your case - you need apply webpack-dev-server on multi compiler level and set the port option. Right now you can set port using the devServer option for first compiler.

    In future we will fix this limitation

  7. Christian24 commented on Feb 6, 2021

    @Christian24
    Author

    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 devServer configurations 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.

  8. Christian24 commented on Feb 6, 2021

    @Christian24
    Author

    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?

  9. alexander-akait commented on Feb 6, 2021

    @alexander-akait
    Member

    @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

  10. alexander-akait commented on Feb 6, 2021

    @alexander-akait
    Member

    Let's keep open, I want to search right way for this or update docs with the limitation (official)

  11. 24 remaining items

  12. evenstensberg commented on Jul 9, 2024

    @evenstensberg
    Member

    @alexander-akait any update on this?

  13. alexander-akait commented on Jul 10, 2024

    @alexander-akait
    Member

    No, we need implement plugin support for devserver

  14. ImStillBlessed commented on Mar 11, 2026

    @ImStillBlessed

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions