Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Remote into Web Component from React giving an error saying " Module does not exist in container" #18323

Closed
pranavbedi opened this issue Apr 15, 2024 · 0 comments

Comments

@pranavbedi
Copy link

Bug report

What is the current behavior?

When I bring the To-Do-List component into the main app, it says it is unable to be found. This error does not happen when i try use a react component but only when I try to use a Web Component.

The error i get is :
container_entry:12 Uncaught (in promise) Error: Module "./ToDoList_remoteEntry.js" does not exist in container.
while loading "./ToDoList_remoteEntry.js" from webpack/container/reference/ToDoList
at eval (container_entry:12:11)

This is the webpack config file in the main app:

`const path = require("path");
const webpack = require('webpack');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { ModuleFederationPlugin } = require("webpack").container;

module.exports = {
entry: "/src/index.js",
output: {
path: path.resolve(__dirname, "dist"),
publicPath: "auto",
},
devServer: {
port: 9000,
},
module: {
rules: [
{
test: /.(js|jsx)$/,
exclude: /node_modules/,
use: ["babel-loader"],
},
{
test: /.css$/i,
use: ["style-loader", "css-loader", "postcss-loader"],
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser',
}),
new ModuleFederationPlugin({
remotes: {
AccountsSummaryApp_Remote:
"AccountsSummaryApp@http://localhost:9001/accountsSummaryApp_remote.js",
AccountDetailsApp_Remote:
"AccountDetailsApp@http://localhost:9002/accountDetailsApp_remote.js",
ToDoList:
"ToDoList@http://localhost:3001/ToDoList_remoteEntry.js",
},
}),
new HtmlWebpackPlugin({
template: "src/index.html",
}),
],
};
`

and this is the webpack config for the To-Do-List component:

`
const HtmlWebPackPlugin = require("html-webpack-plugin");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const Dotenv = require('dotenv-webpack');
const deps = require("./package.json").dependencies;
module.exports = (_, argv) => ({
output: {
publicPath: "http://localhost:3001/",
},

resolve: {
extensions: [".ts", ".tsx", ".jsx", ".js", ".json"],
},

devServer: {
port: 3001,
historyApiFallback: true,
},

module: {
rules: [
{
test: /.m?js/,
type: "javascript/auto",
resolve: {
fullySpecified: false,
},
},
{
test: /.(css|s[ac]ss)$/i,
use: ["style-loader", "css-loader", "postcss-loader"],
},
{
test: /.(ts|tsx|js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
],
},

plugins: [
new ModuleFederationPlugin({
name: 'ToDoList',
filename: 'ToDoList_remoteEntry.js',
exposes: {'./ToDoList': './src/ToDoList.js', // Ensure this is the correct file path
},
shared: {
...deps,
},
}),
new HtmlWebPackPlugin({
template: "./src/index.html",
}),
new Dotenv()
],
});
'

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?
The web component is imported successfully

Other relevant information:
webpack version: 5.65.0
Node.js version: 20.12.0
Operating System: Windows
Additional tools:

@webpack webpack locked and limited conversation to collaborators Apr 16, 2024
@alexander-akait alexander-akait converted this issue into discussion #18326 Apr 16, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant