module-federation / webpack-4

Webpack 4 Plugin For Module Federation
MIT License
42 stars 5 forks source link

TypeError: SyncBailHook is not a constructor #8

Closed entranced closed 1 year ago

entranced commented 1 year ago

I get this error while trying to use the plugin:

C:\src\app\node_modules\mf-webpack4\lib\plugin.js:46
      runtimeFetchContainer: new SyncBailHook(["remote", 'url'])
                             ^

TypeError: SyncBailHook is not a constructor
    at new ModuleFederationPlugin (C:\src\app\node_modules\mf-webpack4\lib\plugin.js:46:30)
    at Object.<anonymous> (C:\src\app\build\webpack.base.conf.js:69:9)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\src\app\build\webpack.dev.conf.js:7:27)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)

Looks like the tapable dependency is used, but not declared anywhere in the package.json. If I install tapable it works fine, but I want to confirm the expected version to be used here.

zhangHongEn commented 1 year ago

Do you have multiple node_modules? "tapable": "^1.1.3" is attached with webpack@4, which scenes will not find tapable

entranced commented 1 year ago

I'm not sure why it failed for me, I do see tapable being used by multiple other deps:

PS C:\src\app> npm list tapable app@2.0.0 C:\src\app ├─┬ eslint-import-resolver-webpack@0.12.2 │ └─┬ enhanced-resolve@0.9.1 │ └── tapable@0.1.10 ├─┬ fork-ts-checker-webpack-plugin@6.5.2 │ └── tapable@1.1.3 ├─┬ html-webpack-plugin@4.5.2 │ └── tapable@1.1.3 ├─┬ nuxt@2.15.8 │ └─┬ @nuxt/webpack@2.15.8 │ ├─┬ hard-source-webpack-plugin@0.13.1 │ │ └── tapable@1.1.3 │ └─┬ postcss-import-resolver@2.0.0 │ └─┬ enhanced-resolve@4.5.0 │ └── tapable@1.1.3 ├── tapable@2.2.1 ├─┬ ts-loader@8.4.0 │ └─┬ enhanced-resolve@4.5.0 │ └── tapable@1.1.3 ├─┬ vue-i18n-jest@0.2.1 │ └─┬ @vue/cli-plugin-unit-jest@4.5.19 │ └─┬ @vue/cli-service@4.5.19 │ └─┬ html-webpack-plugin@3.2.0 │ └── tapable@1.1.3 ├─┬ webpack-cli@3.3.12 │ └─┬ enhanced-resolve@4.5.0 │ └── tapable@1.1.3 └─┬ webpack@4.46.0 ├─┬ enhanced-resolve@4.5.0 │ └── tapable@1.1.3 deduped └── tapable@1.1.3

I had to install it as a dep to get MF4 work for me, but it installed ^2.2.1 -- looks like I should use 1.x.x?

zhangHongEn commented 1 year ago

It turns out that there are multiple tapables, mf-webpack4 may have introduced tapable@0.1.10, it seems that I really need to set it as dependencies

zhangHongEn commented 1 year ago

I haven't tried the version above 2, and it may be possible

zhangHongEn commented 1 year ago

You can install "tapable": "^1.1.3" first, and I will add it to dependencies at night

entranced commented 1 year ago

Will use that one, thanks @zhangHongEn !

zhangHongEn commented 1 year ago

🤝, mf-webpack4@1.4.1 released