Daniel
Daniel

Reputation: 15413

Webpack: Cannot GET /

I have a React microfrontend that was working on Friday, specifically the container/ portion of it.

Now I get Cannot GET /.

I ran a netstat -aon and there is nothing listening on port 8080.

Even if I try to change to another port in Webpack, I get the same result. The webpack configuration for my container:

const {merge} = require('webpack-merge');
const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
const commonConfig = require('./webpack.common');
const packageJson = require('../package.json');

const devConfig = {
  mode: 'development',
  devServer: {
     port: 8080,
     historyApiFallback: true,
  },
  plugins: [
    new ModuleFederationPlugin({
       name: 'container',
       remotes: {
          marketing: 'marketing@http://localhost:8081/remoteEntry.js'
       },
       shared: packageJson.dependencies,
    }),
  ],
};

module.exports = merge(commonConfig, devConfig);

The webpack version I am using is 5.11.0. This is happening on a Windows 10 machine. I have a similar project on a MacBookPro and I am not getting this behavior.

Upvotes: 0

Views: 174

Answers (1)

Daniel
Daniel

Reputation: 15413

I was missing HtmlWebpackPlugin inside my webpack.dev.js file:

const {merge} = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
const commonConfig = require('./webpack.common');
const packageJson = require('../package.json');

const devConfig = {
  mode: 'development',
  devServer: {
     port: 8080,
     historyApiFallback: true,
  },
  plugins: [
    new ModuleFederationPlugin({
       name: 'container',
       remotes: {
          marketing: 'marketing@http://localhost:8081/remoteEntry.js'
       },
       shared: packageJson.dependencies,
    }),
    new HtmlWebpackPlugin({
      tempate: './public/index.html'
    }),
  ],
};

module.exports = merge(commonConfig, devConfig);

Upvotes: 1

Related Questions