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

@mf-types.zip not being generate since 0.2.7 #2827

Open
5 tasks done
ryok90 opened this issue Aug 6, 2024 · 17 comments
Open
5 tasks done

@mf-types.zip not being generate since 0.2.7 #2827

ryok90 opened this issue Aug 6, 2024 · 17 comments
Assignees

Comments

@ryok90
Copy link
Contributor

ryok90 commented Aug 6, 2024

Describe the bug

GenerateTypesPlugin is having trouble generating the zip file for @mf-types.

Replication is just bumping the plugins version to 0.3.3 of an rspack app from mf examples repo.

image.

Reproduction

https://github.com/module-federation/module-federation-examples/tree/master/rspack_hmr/app2

Used Package Manager

pnpm

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M2 Pro
    Memory: 213.69 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v20.10.0/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
    pnpm: 9.5.0 - ~/.nvm/versions/node/v20.10.0/bin/pnpm
  Browsers:
    Chrome: 127.0.6533.89
    Safari: 17.5

Validations

@ScriptedAlchemy
Copy link
Member

@2heal1 can you take a look?

@kondensat01
Copy link

i have same issue on webpack plugin
image

@ScriptedAlchemy
Copy link
Member

does the build crash? or just throw error?

@ryok90
Copy link
Contributor Author

ryok90 commented Aug 9, 2024

does the build crash? or just throw error?

@ScriptedAlchemy
Only warns.
It doesn't crash.
Types are being built, they appear inside the bundle, but they just don't get zipped apparently.

@katarinish
Copy link

katarinish commented Aug 26, 2024

Types are being built, they appear inside the bundle, but they just don't get zipped apparently.

Hi guys! I bumped into the same exact issue, but in my case types are not generated at all. The bundle is built (static JS-chunks + manifest files), but neither /@mf-types folder nor @mf-types.zip is present inside /dist folder

The error i get when i run build script:
image

The /dist folder after build script execution
image

The @mf-types folder is being generated only when i manually try to run the ts-compile command from error message above, which is npx tsc --project <path-to-my-packege>/node_modules/.federation/tsconfig.8e832ac4f46027611fcdf3bf665e47de.json
image

I have "@module-federation/enhanced": "0.3.5" installed (using ModuleFederationPlugin webpack plugin).

Another problem is that dts options does not override the given defaults. When researching the problem, i was trying to give a types-zip-file another name according to the instructions https://module-federation.io/configure/dts#typesfolder :

dts: {
    typesFolder: 'custom',
},

But when i run my build command again with specific typesFolder name, i still meet the same error message as it was:
ENOENT: no such file or directory, open '.../**@mf-types.zip'** saying that @mf-types.zip is missing but not the custom.zip as it is supposed to be.

@katarinish
Copy link

katarinish commented Aug 26, 2024

Some updates to my notes here :)

So if we take a closer look to an error it firstly says that TS compile failed: Error: compile TS failed
Screenshot 2024-08-26 at 18 37 56
and there is the log of the original command which is failed: npx tsc --project <path-to-my-packege>/node_modules/.federation/tsconfig.8e832ac4f46027611fcdf3bf665e47de.json

So if i try to run this command manually i get i few TS erros while compiling. These errros come from @types/ws package:
image
Here is the exact place of code which TS doesnt like https://github.com/DefinitelyTyped/DefinitelyTyped/blame/master/types/ws/index.d.ts#L312

Soooo if i go to node_modules/@types/ws/index.d.ts and manually remove generics from the type (i know it is a dirty hack but wanted to check if it will work) it fixes TS compilatiion. And when i re-run my build command again all the types and zip-file itself generate successfully 🥳
image
image

So the problem of not building @mf-types.zip is the TS error inside @types/ws package:

node_modules/@types/ws/index.d.ts:312:18 - error TS2315: Type 'Server' is not generic.

312         server?: HTTPServer<V> | HTTPSServer<V> | undefined;

This is where this line of code is declared https://github.com/DefinitelyTyped/DefinitelyTyped/blame/master/types/ws/index.d.ts#L312

And HTTPServer comes from import { Server as HTTPSServer } from "https";


my Node version is v18.15.0
"@types/ws" from package-lock.json is: "version": "8.5.12"
Here is where it is inherited from:
image
There is a relative issue web3/web3.js#6303

Rolling back to "@types/ws": "8.5.4" probably fixes the problem

jfyi @2heal1

@igoldny
Copy link

igoldny commented Sep 1, 2024

Do you happen to have any updates on this one?
Had the same issue,
It happens both on my project and module-federation rs-pack example

@2heal1
Copy link
Member

2heal1 commented Sep 2, 2024

because now mf types will use project's tsconfig.json , so you can set "skipLibCheck": true, in tsConfig.json compilerOptions to prevent the error

@efriandika
Copy link

because now mf types will use project's tsconfig.json , so you can set "skipLibCheck": true, in tsConfig.json compilerOptions to prevent the error

I have this in my tsconfig. The same error is still there..
Unable to compile federated types, Error: compile TS failed, the original command is 'npx tsc --project /Users/xxxx/zzzz/node_modules/.federation/tsconfig.6dd5cd1b6230eccdafd02f44d0cfb6a2.json'
Error: ENOENT: no such file or directory, open '/Users/xxxx/dist/@mf-types.zip'

@katarinish
Copy link

I have this in my tsconfig. The same error is still there.. Unable to compile federated types, Error: compile TS failed, the original command is 'npx tsc --project /Users/xxxx/zzzz/node_modules/.federation/tsconfig.6dd5cd1b6230eccdafd02f44d0cfb6a2.json' Error: ENOENT: no such file or directory, open '/Users/xxxx/dist/@mf-types.zip'

Try to run the specified command from the error message (in your case it is npx tsc --project /Users/xxxx/zzzz/node_modules/.federation/tsconfig.6dd5cd1b6230eccdafd02f44d0cfb6a2.json) and see what the TSError looks like

@xiaoluo997
Copy link

Describe the bug

GenerateTypesPlugin is having trouble generating the zip file for @mf-types.

Replication is just bumping the plugins version to 0.3.3 of an rspack app from mf examples repo.

image.

Reproduction

https://github.com/module-federation/module-federation-examples/tree/master/rspack_hmr/app2

Used Package Manager

pnpm

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M2 Pro
    Memory: 213.69 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v20.10.0/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
    pnpm: 9.5.0 - ~/.nvm/versions/node/v20.10.0/bin/pnpm
  Browsers:
    Chrome: 127.0.6533.89
    Safari: 17.5

Validations

Hi guys, I'm also experiencing this problem, when I run pnpm dev and when generating @mf-types type, it reports Error: ENOENT: no such file or directory, open xxx/mf-demo/federation_provider/dist/@mf- types.zip'. After checking, I found that there is no coustom.zip file in the dist directory.
After troubleshooting, we found that there is an error reported for ts types in the project, @my-types.zip generation failed.
error ts:
截屏2024-09-05 下午10 46 42
截屏2024-09-05 下午10 47 14

Then stamp the ts type so he doesn't report errors, and you can generate the @mf-types.zip file
截屏2024-09-05 下午10 49 22
截屏2024-09-05 下午10 49 42

@2heal1
Copy link
Member

2heal1 commented Sep 20, 2024

@ryok90 upgrade to 0.6.5 , the issue should be fixed , if still has error , please tell me , i will fix it soon

@maitrungduc1410
Copy link

maitrungduc1410 commented Sep 22, 2024

I'm still facing this issue for vue project:

import { defineConfig } from "@rsbuild/core";
import { pluginVue } from "@rsbuild/plugin-vue";
import { ModuleFederationPlugin } from "@module-federation/enhanced/rspack";

export default defineConfig({
  plugins: [pluginVue()],
  dev: {
    assetPrefix: true,
  },
  tools: {
    rspack: {
      output: {
        uniqueName: "vue_mfe_app",
      },
      plugins: [
        new ModuleFederationPlugin({
          name: "vue_mfe_app",
          exposes: {
            "./App": "./src/App.vue",
          },
          shared: ["vue"],
          filename: "remoteEntry.js",
        }),
      ],
    },
  },
});

Note the line "./App": "./src/App.vue",

Screenshot 2024-09-22 at 11 39 14 AM
Unable to compile federated types, Error: compile TS failed, the original command is 'npx tsc --project /Users/bytedance/Code/Personal/mfe-multi-bundlers/vue-mfe-app/node_modules/.federation/tsconfig.425616e1a5a10887de70d1a4135651e6.json'

@pganster
Copy link

pganster commented Oct 3, 2024

We've upgraded to this version and can confirm that the types are now generated as expected.

For those still facing this issue: Ensure you do not have Typescript errors within your project. When we had errors this lead to the mf-types.zip not being generated. If that file was missing for a remote app, the host app would then delete the types of the remote app from its mf-types folder too. So ensure there are no Typescript errors in any of your applications.

@jeremy-leclerc
Copy link

jeremy-leclerc commented Oct 4, 2024

I came across this issue as well and was able to resolve by changing the exposed path from the root of the project to it's relative path. The problem was hard to identify because using the path from the root of the project worked when the type generation was disabled.

Configuration that caused the failure:

new ModuleFederationPlugin({
          ....
          exposes: { './Foo': '/src/components/Foo.tsx' },
          ...
})

Fixed configuration:

new ModuleFederationPlugin({
          ....
          exposes: { './Foo': './src/components/Foo.tsx' },
          ...
})

@ScriptedAlchemy
Copy link
Member

Yeah. Same rules as package.json exports field

@YanPes
Copy link
Contributor

YanPes commented Oct 18, 2024

In my point of view the solution is already addressed here by:

  • @2heal1 (version update + solution path to adding custom strategy runtime plugin)
  • @pganster (ensure clean build by resolving all TS issues beforehand)
  • @jeremy-leclerc (making sure the exposes field is poperly set)

I will write a short doc for this on the Error Catalog guide
After that we can close this issue.

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