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

getting error of shared module doesnot exist #643

Open
pritiranjan-r opened this issue Nov 26, 2024 · 0 comments
Open

getting error of shared module doesnot exist #643

pritiranjan-r opened this issue Nov 26, 2024 · 0 comments

Comments

@pritiranjan-r
Copy link

error message:
Uncaught Error: Shared module is not available for eager consumption: webpack/sharing/consume/default/react/react
at webpack_require.m. (bundle.js:1165:53)
at webpack_require (bundle.js:357:31)
at fn (bundle.js:701:20)
at eval (index.js:2:63)
at ./src/index.js (bundle.js:37:1)
at webpack_require (bundle.js:357:31)
at bundle.js:1278:36Understand this errorAI
hook.js:608 Initialization of sharing external failed: ScriptExternalLoadError: Loading script failed.
(missing: http://localhost:4173/assets/remoteEntry.js)
overrideMethod @ hook.js:608Understand this warningAI

THis is my vite config file
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import federation from '@originjs/vite-plugin-federation'

// https://vitejs.dev/config/
import svgr from 'vite-plugin-svgr';

export default defineConfig({
plugins: [
react(),
svgr({
include: 'src/**/*.svg',
}),
federation({
name: "viteRemote",
filename: "remoteEntry.js",
exposes: {
'./VbcHeader': './src/components/header'
},
shared: ['react','react-dom']
})
],
build: {
modulePreload: false,
target: 'esnext',
minify: false,
cssCodeSplit: false
}
})

and this is my webpack configuration

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

/** @type {import('webpack').Configuration} /
module.exports = {
entry: './src/main',
mode: 'production',
target: 'web',
devtool: 'eval-source-map',
resolve: {
extensions: ['.js', '.jsx'],
},
output: {
path: path.resolve(__dirname, "dist"), // Output directory
filename: "bundle.js", // Output file name
clean: true, // Cleans the output directory before each build
libraryTarget: 'module',
},
experiments: {
outputModule: true, // Enable experimental ESM output
},
target: 'web', // Target browsers that support ESModules
optimization: {
minimize: true,
},
performance: {
hints: false,
maxEntrypointSize: 512_000,
maxAssetSize: 512_000
},
module: {
rules: [
{
test: /.svg/,
type: 'asset/resource'
},
{
test: /.css$/i,
use: ["css-loader"],
},
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: [
["@babel/preset-react", {"runtime": "automatic"}]
],
},
},
],
},
plugins: [
new HtmlWebpackPlugin(),
new ModuleFederationPlugin({
name: 'webpackHost',
filename: 'remoteEntry.js',
remotes: {
viteRemote: viteRemote@http://localhost:4173/assets/remoteEntry.js,
},
shared: {
react: {
singleton: true,
},
'react-dom': {
singleton: true,
},
},
}),
],
devServer: {
port: 8080,
headers: {
'Access-Control-Allow-Origin': '
',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
},
},
};

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

1 participant