Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Trying to add vue to react microfrontend returns error fn is not a function while loading #3171

Unanswered
iodum asked this question in Q&A
Discussion options

I try to add Vue app to my microfrontend react application.

The configuration inside webpack.config.js of vue app is like this:

 optimization: {
 runtimeChunk: false,
 },
 devServer: {
 headers: {
 "Access-Control-Allow-Origin": "*",
 },
 },
 output: {
 uniqueName: "hello_vue",
 publicPath: "http://localhost:4202/",
 filename: '[name][contenthash].js',
 clean: true,
 },
 module: {
 rules: [
 {
 test: /\.vue$/,
 use: "vue-loader",
 },
 ],
 },
 resolve: {
 extensions: [".vue", ".js"],
 },
 plugins: [
 new container.ModuleFederationPlugin({
 name: "hello_vue",
 filename: "remoteEntry.js",
 exposes: {
 "./VueApp": "apps/hello_vue/src/bootstrap",
 },
 shared: {
 ...dependencies,
 },
 }),
 new VueLoaderPlugin(),
 ],

The configuration of react app:

 plugins: [
 new container.ModuleFederationPlugin({
 name: "shell",
 remotes: {
 hello_vue: "//localhost:4202/remoteEntry.js",
 },
 runtime: false,
 library: { type: "module" },
 shared: {
 ...dependencies,
 },
 }),
 ],

Also, decalre module in react app:

declare module "hello_vue/VueApp";

In react app I created a new component for loading vue app:

import React, { useRef, useEffect } from "react";
import { mount } from "hello_vue/VueApp";
export default () => {
 const ref = useRef(null);
 useEffect(() => {
 mount(ref.current)
 }, [])
 return <div ref={ref} />;
};

Both application are successfully started, but I get an error

TypeError: fn is not a function
while loading "./VueApp"

Also, try to change config like:

remotes: {
 hello_vue: "hello_vue@http://localhost:4202/remoteEntry.js",
},

but get a new error

Uncaught TypeError: Failed to resolve module specifier "hello_vue@http://localhost:4202/remoteEntry.js". Relative references must start with either "/", "./", or "../".

What could be the cause of this problem?

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

@iodum did you find the solution ?

You must be logged in to vote
1 reply
Comment options

Yes, this solutions works for me:

 plugins: [
 new container.ModuleFederationPlugin({
 name: "shell",
 remotes: {
 hello_vue: "hello_vue@/_vue_app/remoteEntry.js",
 },
 runtime: false,
 library: { type: "module" },
 shared: {
 ...dependencies,
 },
 }),
 ],

where hello_vue - name of vue app, _vue_app - publicPath of vue app:

plugins: [
 new container.ModuleFederationPlugin({
 **name: "hello_vue",**
 filename: "remoteEntry.js",
 exposes: {
 "./VueApp": "apps/hello_vue/src/bootstrap",
 },
 shared: {
 ...dependencies,
 },
 }),
 output: {
 **publicPath: "/_vue_app/",**
 },
 new VueLoaderPlugin(),
 ],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /