Skip to content
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

[webpack-dev-middleware] ConcurrentCompilationError: You ran Webpack twice. Each instance only supports a single concurrent compilation at a time. #4947

Closed
gonandriy opened this issue Jul 18, 2023 · 4 comments

Comments

@gonandriy
Copy link

gonandriy commented Jul 18, 2023

Bug report

Actual Behavior

If I export multiple configurations, as described here
https://webpack.js.org/configuration/configuration-types/#exporting-multiple-configurations
and run webpack serve
I see this error
image

And watching for files changing does not work!

webpack.config.js is very simple

const path = require('path');

module.exports = [
  {
    mode: 'development',
    entry: './src/index.js',
    output: {
      filename: 'main.js',
      path: path.resolve(__dirname, 'dist/default/'),
    },
    devtool: 'inline-source-map',
    devServer: {
      static: './dist/default',
    },
  },
  {
    mode: 'development',
    entry: './src/admin.js',
    output: {
      filename: 'admin.js',
      path: path.resolve(__dirname, 'dist/admin/'),
    },
    devtool: 'inline-source-map',
    devServer: {
      static: './dist/admin',
    },
  }
];

Expected Behavior

The webpack dev server is running and watches after file changing and always serve the most recent compiled content.

@9at8
Copy link

9at8 commented Aug 21, 2023

Can repro 👍

    "webpack": "5.88.2",
    "webpack-cli": "5.1.4",
    "webpack-dev-server": "4.15.1"

@sentience
Copy link

sentience commented Nov 9, 2023

Looks like a dupe of webpack/webpack-cli#3666, although that one didn't mention that watching for file changes was broken.

@sentience
Copy link

sentience commented Nov 9, 2023

I believe this is actually a misconfiguration.

Per webpack/webpack-cli#2408 (comment), the correct way to configure webpack-dev-server in a multi-config setup is to add the devServer block only to the first config:

const path = require('path');

module.exports = [
  {
    entry: './src/index.js',
    
    devServer: {
      static: './dist/default',
    },
  },
  {
    entry: './src/admin.js',}
];

The one instance of webpack-dev-server will serve files for both of your configurations! This is very convenient, but it does present challenges if you want devServer to be configured differently for each of your webpack configs (e.g. in @gonandriy's case above, having different static values). This does not appear to be possible, except by running entirely separate processes for each webpack-dev-server, using the --config-name flag to select which configuration to run for each.

@alexander-akait
Copy link
Member

Close in favor webpack/webpack-cli#2408, we are still working on it, current solution is using #4947 (comment)

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

4 participants