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

TypeError: lib.init is not a function #396

Open
mostafa-raafat opened this issue Apr 8, 2023 · 37 comments
Open

TypeError: lib.init is not a function #396

mostafa-raafat opened this issue Apr 8, 2023 · 37 comments

Comments

@mostafa-raafat
Copy link

mostafa-raafat commented Apr 8, 2023

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
Copy link
Author

@ruleeeer Could you help me with this issue?

@baijunjie
Copy link
Contributor

Same problem with vite

@MatheusKindrazki
Copy link

I have the same problem 😢

@mjangir
Copy link

mjangir commented May 22, 2023

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

@mostafa-raafat
Copy link
Author

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

@theart84
Copy link

This configuration:
image
Still defines it as esm:
image

@mostafa-raafat
Copy link
Author

@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.

@theart84
Copy link

@mostafa-raafat
image
He stubbornly sets these parameters.

@theart84
Copy link

theart84 commented May 23, 2023

image

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

image Then everything will be determined correctly

@mjangir
Copy link

mjangir commented May 23, 2023

@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.

@lokingdav
Copy link

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.

@clxx
Copy link

clxx commented Jul 14, 2023

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

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

@zhoutaoqq
Copy link

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

@erkanisuf
Copy link

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

@mostafa-raafat
Copy link
Author

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

@terence-g-20230331
Copy link

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.

@mostafa-raafat
Copy link
Author

mostafa-raafat commented Aug 14, 2023

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

@hendry91
Copy link

hendry91 commented Aug 19, 2023

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

@mostafa-raafat
Copy link
Author

mostafa-raafat commented Aug 20, 2023

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

@hendry91
Copy link

@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

@lowhan28
Copy link

lowhan28 commented Aug 30, 2023

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

@imycod
Copy link

imycod commented Oct 11, 2023

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
Copy link

imycod commented Oct 11, 2023

image
image
image

@imycod
Copy link

imycod commented Oct 12, 2023

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
Copy link

imycod commented Oct 12, 2023

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

@cp-sumi-k
Copy link

cp-sumi-k commented Oct 12, 2023

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

@laocker96
Copy link

laocker96 commented Oct 21, 2023

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

@pank-j
Copy link

pank-j commented Nov 2, 2023

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

@damtzi
Copy link

damtzi commented Nov 15, 2023

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.

@ChenReuven
Copy link

ChenReuven commented Mar 5, 2024

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

@azhargraha
Copy link

any update on this? still facing the same error Uncaught TypeError: lib.init is not a function
i'm using Nuxt.js (Vite) as host and Next.js (Webpack) as remote.

@arnanta
Copy link

arnanta commented Jul 17, 2024

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

@mostafa-raafat Can you please share the configs of both the remote and host?

@arnanta
Copy link

arnanta commented Jul 17, 2024

I am stuck still. Using Webpack in the remote and vite in host. It keeps on saying lib.init is not a function. Tried all the means @mostafa-raafat

@S-unya
Copy link

S-unya commented Oct 17, 2024

FWIW, for a vite application loading webpack federated modules, there were a few things that had to be in place for me to load them successfully:

HOST:

  • there was nothing special necessary beyond the base example in the root readme of this repo, e.g. you need to use the from: "webpack" setting in remotes

REMOTE:

  • As above, ensure libraryTarget: 'module', setting is in your output
  • And to support this, you will need the experiments: {outputModule: true}, in the base webpack config
  • Also library: { type: 'module' }, needs to go in the modulefederation plugin settings, at the same level as name
  • Finally, I found, the most robust setting for the shared components was to provide import: false and to make sure that version was set.

Hope that helps

@GabrielBursi
Copy link

FWIW, for a vite application loading webpack federated modules, there were a few things that had to be in place for me to load them successfully:

HOST:

  • there was nothing special necessary beyond the base example in the root readme of this repo, e.g. you need to use the from: "webpack" setting in remotes

REMOTE:

  • As above, ensure libraryTarget: 'module', setting is in your output
  • And to support this, you will need the experiments: {outputModule: true}, in the base webpack config
  • Also library: { type: 'module' }, needs to go in the modulefederation plugin settings, at the same level as name
  • Finally, I found, the most robust setting for the shared components was to provide import: false and to make sure that version was set.

Hope that helps

it have worked for me, thanks !

@arolonger
Copy link

@GabrielBursi could you share full vite and webpack config? Thanks in advance

@GabrielBursi
Copy link

@GabrielBursi could you share full vite and webpack config? Thanks in advance

remote (webpack)

webpack

host (vite)

vite

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