vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

TypeError: lib.init is not a function

Open mostafa-raafat opened this issue 2 years ago • 39 comments

Just trying to load a webpack remote That I'm sure 100% it work as i use it in other webpack projects.

As you can see it load with 200 so the url itself is correct Screenshot 2023-04-08 at 17 37 54 Screenshot 2023-04-08 at 17 37 39

Versions originjs: ^1.2.1 node: 15.14.0

And this is a child vite.config.js I tried to use 'var' | 'esm' | 'systemjs' but all of them return same error Screenshot 2023-04-08 at 17 33 22

What is Expected? to display the remote entry in my parent component

What is actually happening? nothing loads and throws lib.init is not a function error Screenshot 2023-04-08 at 17 33 03

mostafa-raafat avatar Apr 08 '23 15:04 mostafa-raafat

@ruleeeer Could you help me with this issue?

mostafa-raafat avatar Apr 17 '23 08:04 mostafa-raafat

Same problem with vite

baijunjie avatar Apr 27 '23 02:04 baijunjie

I have the same problem 😢

MatheusKindrazki avatar May 11 '23 12:05 MatheusKindrazki

I got it fixed. Add format: 'var' also in the remote configuration.

mjangir avatar May 22 '23 09:05 mjangir

@mjangir could you share your webpack.config file please?

mostafa-raafat avatar May 23 '23 11:05 mostafa-raafat

This configuration: image Still defines it as esm: image

theart84 avatar May 23 '23 12:05 theart84

@theart84 I think @mjangir meant to update your webpack.config by adding remoteType: 'var' I didn't try it yet but will try it today night and will let you know if it work.

mostafa-raafat avatar May 23 '23 12:05 mostafa-raafat

@mostafa-raafat image He stubbornly sets these parameters.

theart84 avatar May 23 '23 12:05 theart84

image

I think I got it, I need to write the settings like this.

image Then everything will be determined correctly

theart84 avatar May 23 '23 12:05 theart84

@mjangir could you share your webpack.config file please?

Our remote app is a CRA application with CRACO module federation config which produces a webpack library output.

mjangir avatar May 23 '23 12:05 mjangir

I am facing the same issues. In my case I am setting up react.js + typescript + vite project as parent to use the remote project which uses webpack and vue.js. I tried everything in this thread however I still face the same issue.

lokingdav avatar Jun 12 '23 19:06 lokingdav

Do you use this? It causes such an error as well:

// webpack.config.js
// ...
optimization: {
  // ...
  runtimeChunk: 'single'
}

clxx avatar Jul 14 '23 01:07 clxx

I get the same issue, can anyone provide any suggestions?

zhoutaoqq avatar Jul 17 '23 03:07 zhoutaoqq

I am having same issue with Vite Host and React Webpack remote.

erkanisuf avatar Jul 19 '23 12:07 erkanisuf

@ruleeeer Do you have any updates about this issue as it's really critical?

mostafa-raafat avatar Jul 19 '23 12:07 mostafa-raafat

having the same issue that trying to use a webpack remote module from vite host, and keep seeing this :

lib.init is not a function
TypeError: lib.init is not a function
    at http://localhost:5174/@id/__x00__virtual:__federation__:53:19

Really appreciate if anyone can share a working case with the configs, solutions or best practices.

terence-g-20230331 avatar Jul 21 '23 05:07 terence-g-20230331

Hello everyone I have a good news today. I was able to create a working demo Remote => webpack and Host => Vite Both configuration should use esm as output format. Link for the PR https://github.com/originjs/vite-plugin-federation/pull/480

Webpack configurations Screenshot 2023-08-15 at 00 22 32 Screenshot 2023-08-15 at 00 22 44

Vite configurations Screenshot 2023-08-15 at 00 22 17

mostafa-raafat avatar Aug 14 '23 22:08 mostafa-raafat

Hi @mostafa-raafat I'm new to the federation and I having the same issue when using the nextjs, do you have any idea how to fix this? Thanks.

vite.config.js image

next.config.js image

image

hendry91 avatar Aug 19 '23 10:08 hendry91

Hi @hendry91 did you update vite configuration build output format to esm?

mostafa-raafat avatar Aug 20 '23 09:08 mostafa-raafat

@mostafa-raafat Thank for you reply, I've added the build: { target: 'esnext', rollupOptions: { output: { format: 'esm' } } }, but it doesn't work, still getting the same error. image

hendry91 avatar Aug 21 '23 15:08 hendry91

Hi @mostafa-raafat, may I ask any solution for https://github.com/originjs/vite-plugin-federation/issues/396#issuecomment-1686558061 ? cause I also face same issue. Really appreciate can share some solutions. Thanks

lowhan28 avatar Aug 30 '23 10:08 lowhan28

I'm not sure why, but I did indeed resolve this issue. It might be related to the shared and manualChunks configurations. In two new Vite Vue projects, when I configured manualChunks and shared for the remote module, Vue was bundled into a new file with a different name, and the host could use it. However, in an existing online project, I encountered a lib.init problem when I configured shared along with `manualChunks.

imycod avatar Oct 11 '23 14:10 imycod

image image image

imycod avatar Oct 11 '23 14:10 imycod

Hi @mostafa-raafat, may I ask any solution for #396 (comment) ? cause I also face same issue. Really appreciate can share some solutions. Thanks

try manualChunks shared

imycod avatar Oct 12 '23 02:10 imycod

Hello everyone I have a good news today. I was able to create a working demo Remote => webpack and Host => Vite Both configuration should use esm as output format. Link for the PR #480

Webpack configurations Screenshot 2023-08-15 at 00 22 32 Screenshot 2023-08-15 at 00 22 44

Vite configurations Screenshot 2023-08-15 at 00 22 17

if add manualChunks options,what happen

imycod avatar Oct 12 '23 02:10 imycod

I am working with Nuxt.js(Host) -> vite and Next.js(remote) -> webpack, facing the same issue.

Nuxt.config.js

Screenshot from 2023-10-12 11-09-23

Next.config.js

Screenshot from 2023-10-12 11-10-10

Here is error Screenshot from 2023-10-12 11-11-07

Nothing has been worked

cp-sumi-k avatar Oct 12 '23 05:10 cp-sumi-k

Any solution so far? I'm stuck with Vite + React Host and NextJS as Remote

This is my conf (not working)

Remote config (NextJS) image

Host config (Vite + React) image

laocker96 avatar Oct 21 '23 01:10 laocker96

Any updates or progress on this? I am facing a similar issue. I have Nuxt(remote) and Vue3/ VIte(host). Nuxt.config => Screenshot 2023-11-02 at 10 50 04

After build, this is how my remoteEntry.js looks like: Screenshot 2023-11-02 at 10 53 38

Vite.Config => Screenshot 2023-11-02 at 10 51 35

.. and just like others, I am constantly being troubled by this message: Screenshot 2023-11-02 at 10 54 48

pank-j avatar Nov 02 '23 09:11 pank-j

Hello, are there any updates on this? Have the same error Uncaught TypeError: lib.init is not a function using a next js app as remote and react+vite app as host.

damtzi avatar Nov 15 '23 17:11 damtzi

is there any update? still have the same issue

Host = Vite Remote = Webpack (Craco) and also i try regular webpack and it dosnt work.

i try to understand is it "safe" to take this plugin to work with remote Webpack, cause currently AFAIS there is no solution for that :(

Thanks 4 your effort

ChenReuven avatar Mar 05 '24 19:03 ChenReuven